I have always had the feeling that they can only turn into a ghost when they die through physical means. Like when nearly headless nick was hacked so many times, but Dumbledore was killed by a curse. Kinda like George's ear that can't grow back after beng affected by dark magic.