They are allowed to ask the question.
They are not allowed to use the information in making the hiring decision.
If you want my personal opinion, it's stupid of them to ask, because if they don't ask, they can't be accused of using the information illegally. But asking is not in and of itself illegal.
And yes, they can ask if you are gay or a lesbian. Federal law does not protect sexual orientation; if you are in a state that does protect it, the same answer as above would apply.