Puck doesn't explain precisely why he changes Bottom's head into an ass's head, but he does seem to resent that the uncouth mechanicals or "homespuns" are so near his queen, saying:
What hempen homespuns have we swaggering here,
So near the cradle of the fairy queen?
He listens in on Bottom's acting and finds it strange, then uses magic to turn his head into an ass's head. This is appropriate because Puck considers Bottom an "ass," or fool, which is, in fact, what he thinks most mortals to be. It is also a pun
on Bottom's name, as human buttocks are called both bottoms and asses.
When Bottom, who has no idea about his transformation, despite the fact that his appearance has frightened ways his friends, awakes Titania, she says:
What angel wakes me from my flowery bed?
She falls in love with Bottom instantly, because Oberon has administered a love potion to her eyes to insure she will fall in love with the first person she sees. Oberon does this to divert her from the Indian boy she has adopted. Oberon wants the boy for his own entourage, but Titania is insistent that she keep him. She made a promise to his mortal mother that should anything happen to her, she would raise the boy. She was very close with the mother, so she doesn't want to break this promise, even at the cost of angering Oberon. Oberon realizes that only by having Titania fall in love with someone else will he divert her enough so that he can talk her into giving up the boy.
Someone like Titania falling in love with a lower class man with an ass's head helps to illustrate Shakespeare's point that love is blind and a form of lunacy.