That the autofocus did the right thing in the first photo is frankly miraculous (see the second photo for full context — shot it through a keyhole, just about). That the autofocus botched the job taking the photo of the other two mushrooms is unsurprising.