I have been searching for a while now and I came to the conclusion that when you fix the aperture ring of Nikon 1.4D lens on lowest stop, then we can change the aperture using command dial, plus the 1.4D version also provides the auto focus on bodies with a built-in AF motor. Why then buy the 50mm 1.4G or 1.8G instead of 1.4D or 1.8D?
The two Nikon G lenses mentioned in the question are AF-S lenses that have an internal focus motor and can be used with any modern Nikon DSLR with auto focus fully functional. The two Nikon D lenses mentioned in the question are AF lenses that do not have an internal focus motor and must be used with a camera body that includes a focus motor in the body via a mechanical linkage if autofocus is desired.
The D3xxx and D5xxx series bodies (as well as some, but not all of the older Dxx bodies) do not have an focus motor in the body and require an AF-S lens for autofocus. The AF Nikkor D lenses must be focused manually when used on a non-motorized body.
Even when using a body that does include a focus motor, the Silent Wave motors in most AF-S lenses are faster and quieter than the camera's focus motor and screw drive linkage. The optics in the G series of lenses are newer and generally better than the optics in most of the corresponding D series lens.
For more regarding the differences between these two particular 50mm f/1.8 lenses, please see What's the difference between using a 50mm f/1.8G and a 50mm f/1.8D with a Nikon D80?
The main reason someone would choose a G version of the 50/1.4 over the D version is if you're shooting a D3x00/D40 or D5x00/D60 body, which doesn't have a focus motor in it. On those bodies, the AF D versions do not autofocus, while the AF-S G versions do.
There is also the fact that G versions are typically much newer optical designs, with increased performance. A lot of the G versions are digital-era designs, while some of the D versions are film-era. Sharpness and maximum aperture aren't everything when it comes to lens performance. The G version of the 50/1.4 looks to have better contrast and CA control than the D version when wide open (see: the-digital-picture side-by-side).
When comparing G and D lenses you have to do it on an individual lens basis and not a generalisation regarding each type. e.g. some G lenses do not have a built in autofocus motor and some D lenses do. G lenses include the D distance information. G lenses do not have an aperture ring.
When Nikon changes the designation of a lens sometimes it is improved and sometimes it isn't. Sometimes the autofocus is changed, sometimes the optics are and other times neither.
AF-I and AF-S lenses have an autofocus motor in them whether they G or D. e.g. the AF-S Nikkor 28-70 mm f/2.8 D lens has a motor. The Nikon 28-200mm f/3.5-5.6 AF-G does not have a motor.
Sometimes a D lens can have a better build quality.