So how can one learn to play by ear?

Remember, music is a language. Take any elaborated sentence and try re-structuring the sentence in your own words. Subconsciously, while doing so, you actually reduce the elaborated sentence to its simplest form before attempting to re-structure it with your own vocabulary.
For music, we do the same. We cannot learn from pre-arranged (elaborated) score sheets and play note for note. The learning process should begin from fake sheets. A fake sheet is a score sheet that consists of only right-hand, single-note melody and chords. It is literally the skeleton of any piece of music. Melody + Chords = Song. Both of these elements are the essentials most musicians rely on.
‘Only with a fake sheet, you can then first learn to improvise.’
The root of improvisation is the use of chords. Chords are the building blocks in every song; every melody is based upon chords. If you have a significant understanding of improvising melody with chords, playing by ear becomes much easier.
The process of learning to play by ear is not by listening first, but rather through improvising.’
Improvising = Speaking. Speaking is undeniably the best way to learn any language. Because, when you speak, you listen to yourself at the same time. The more you improvise the better you become at listening. It goes hand in hand.

Q: But why do you need scores (fake sheets) when you are suppose to play by ear?

Ans: Simply because musicians play by ear, not by memory. You can replicate a song with the chords in your head, playing by ear without anything written down. But with millions of songs on the market, you cannot possibly remember the nuances of each of them.

Q: So you mean, I have to read music notes?

Ans: If you are able to read music notation, it is to your advantage. However, if you are unable to do so and do not wish to learn to read as well, it is perfectly fine, taking into consideration that you are learning mostly for leisure purposes. It is also one of the primary reasons many have given up music because they believe that reading is necessary. Having said so, the very least you should learn to read are musical alphabets (C, D, E, F, G, A, B) and fake sheets (with chord symbols).