How do church musicians learn to play hymns by ear if music lessons never really focus on playing by ear? I have met many organists who play hymns by ear but I never understood how they learned it. Standard piano lessons don't focus on playing by ear as repeating what is in a score is what most teachers want to teach. Church musicians study the theory of muisc, eg harmony, but this is not the same as playing by ear.
I attended course for church musicians. One thing is, the number of hymns is finite. Another thing is, that in your church probably do not play all of them. Moreover the chord progressions in those hymns are pretty similar. In another words, the more hymns you learn to play, the faster you learn another one. Until it become instant.
There are another tricks that can help you. One of them is a "moving seventh chord". It sounds like jazz. E.g. if you play in C major, you start with major seventh (c+e+g+b) and just play your right hand and move to another seventh (d+f+a+c) than (e+g+b+d) or back to (c+e+g+b). Than you can go back and forth to adjecent tones.
Another trick is "pentatonic fog". Just play melody in bass and random fast notes from pentatonic scale over it. E.g. in C major just play C, D, E, G or A.
Typical music school program includes many classes besides learning the instrument, like music history, theory and ear training. Ear training focuses on recognizing and singing intervals and chords and writing down music (melodies, rhythms, multi voice compositions) by ear. Of course one doesn't have to attend music school to train their ears, but one needs to work on their ear training to play by ear.
In a nutshell: trial and error
Even without any lessons at all, if you spend some time with an instrument, you'll probably figure out how to play something with it.
On top of that, if you can watch someone play, and/or learn other musical skills, and/or have some extra talent of your own, then your skills will naturally develop even faster and to a higher degree.
All in all, it's not very different from how we learn your own mother language: listening, imitation, feedback, and practice. You will notice that formal training, while helpful for refining it, is not actually necessary.
Playing by ear is resulting of solfege and the theory of harmony. Solfege means singing intervals and identifying chords and tunes by ear (sight reading). This belongs to every study of music.
A church musician normally might not always have all this knowledge in his baggage. I starte also with trial and error and improvising songs and choruses. This was a great advantage when studying music theory.