Why did Shakespeare sometimes write prose instead of blank verse?
First, lets define the difference between the two. Prose is defined as "ordinary language". It is the language that people speak in, and doesn't contain any of the metrical structure of poetry.
Blank verse is specifically a type of poetry. It does have meter (Shakespeare stuck mostly to iambic pentameter), but it doesn't have rhyme.
To answer your question - authors just whichever writing style best suits their purpose. The benefit to blank verse is that it give emphasis to certain lines. It is easier to remember a line that is is a certain beat - which is why we remember the lyrics of songs, whether they rhyme or not. Verse also suggests more formality. So, if you have two kings addressing each other about going to war, you might as an author want to use verse to give the exchange more importance.
In a similar way, you might as an author want to use prose when you are giving the language of common people, or maybe when you are deliberately trying to make a situation or scene seem less important.
The answer will be different depending on the text of Shakespeare we are discussing. Let me give you one example from Macbeth, however. Consider these two lines from Lady Macbeth:
Come, you spirits
that tend on mortal thoughts, unsex me here
This is a noble woman who wants to be queen, and who is asking the spirits to help here have the manly strength and courage to follow through on a murder plot. If you read the lines out loud, you can hear the beat of iambic pentameter following along with her request.
However, in another scene, a few unnamed men have come together to murder a friend of Macbeth. A murderer is discussing where and when to expect the victim.
Almost a mile, but he does usually -
So all men do - from hence to the palace gate.
Here, there is no supernatural or overly thematic purpose to the spoken words. It is plot driven in nature, and so verse is not needed to emphasize what is going on. Just remember that all authors have purpose for the style of writing they choose - define the style of writing, and you should be able to explain why it suits the particular theme or text.