The 50mm f/1.8 AF will meter on the D40, it does have a chip. But it will not AF.
You have to set all[1] Nikkor lenses with aperture rings to the smallest aperture in order for Program and Shutter priority modes to work. The reason is that the camera body will set the aperture at the moment of taking the shot in these modes, and the aperture has to be in a "known state" for this to work.
The lock is simply a convenience to avoid the aperture ring moving accidentally.
If you look at Nikon's G lenses - the ones without an aperture ring - you'll notice the aperture blades are stopped down all the way when the lens is unmounted. This is the same principle at work.
It's been a while since I used the D40 but I do think you have to set the aperture on the camera body - press and hold the exposure compensation button and move the thumbwheel.
[1] all lenses confirming to the AI-s spec (including AF lenses)