If teams are asking these questions, it's because they know they can get away with it.
And this in no way justifies the question, but I imagine some teams don't care about the players orientation, but do care how he reacts when asked about it. There are homophobes in the locker room. The coaches and GMs want to be sure they can play together.
Also, asking "are you gay?" is a quick way to expose those homophobes.