Yes... all LGA 775 sockets will fit all LGA 775 processors but it doesn't mean they will all fit every motherboard or case.
You have to look at your motherboard layout and case size to make sure the heat sink you are looking at will fit. There are time a heat sink can get in the way of the RAM slots or board chipset cooling, so they won't work. Also, the heat sink may be to large to fit into your case, so you have to look at that.
The P4 cooler would physically work because it uses the same socket, but it may not provide sufficient cooling for the Pentium D. Intel uses different sized coolers based on the heat output of the chip. The Pentium D likely came with a bigger cooler than the P4 did.
Definitely get the right cooler for a Pentium D they are space heaters they run really hot especially if its a Smithfield core. Preslers run a little cooler being 65nm but still need a sufficient heat sink to be properly cooled.