The ulimate reason is that a dam creates a body of water that makes a relatively safe neighborhood for a beaver family. But it is very likely that the beaver is unaware of this. The proximate reason, i.e. the real reason as far as the beaver is concern, is that he hates the sound of running water!
Researchers have shown that if you place headspeakers playing the sound of running water at proximity to beavers, the beavers will do all what they can to stop it! In one experiment, the beavers covered the headspeaker with mud until the sound stopped...