He’s the official lessee of the apartment, which is apparently relatively near school, and in Leonard’s price range, and isn’t too unbearable as a roommate. Part of his not being too unbearable as a roommate is accomplished by being friendly with him.
Thus Leonard became friends with him.
As Howard stated outright in the episode where Sheldon tries to make more friends ‘well, we liked Leonard’ - he, Raj, and, later, Penny, became friends with Leonard, and picked up Sheldon as an occasionally infuriating, but usually just prickly, and sometimes kind of amusing package deal.
I’ve been in that sort of situation (due to class assignments, or living arrangements, etc) more than once (hell, I’ve probably been the Sheldon of this equation more than once).