Short answer
Yes. A person who feels drawn to the same sex can be a Muslim, and a good one. Islam judges what a person does, not the feelings they have. The Prophet (ﷺ) said Allah (﷾) forgives the thoughts in people's minds that they do not act on or speak of. What Islam forbids is sex outside marriage between a man and a woman. That rule is the same for everyone, and the Qur'an names same-sex acts among the forbidden. A Muslim who struggles with any desire, or sometimes falls, is still a Muslim. He must sincerely repent and try to avoid doing it again, and Allah (﷾) is Most Merciful. No Muslim may mock, harm or threaten anyone. Allah (﷾) looks at hearts and deeds, not at faces.
Full explanation
Feelings are not sins
The Prophet (ﷺ) said Allah (﷾) has forgiven his people the thoughts and urges that rise in their hearts, as long as they do not speak of them or act on them. The Qur'an says Allah (﷾) places on no soul a burden greater than it can bear. So a man or woman who feels drawn to the same sex has done nothing wrong by feeling it. Islam does not ask anyone to change what he feels. It asks him to guard what he does, as it asks of every believer.
Abu Huraira reports that the Prophet (ﷺ) said Allah has forgiven his people the evil thoughts that pass through their minds, as long as they do not speak of them or act on them.
“On no soul doth Allah Place a burden greater than it can bear. It gets every good that it earns, and it suffers every ill that it earns. (Pray:) "Our Lord! Condemn us not if we forget or fall into error; our Lord! Lay not on us a burden Like that which Thou didst lay on those before us; Our Lord! Lay not on us a burden greater than we have strength to bear. Blot out our sins, and grant us forgiveness. Have mercy on us. Thou art our Protector; Help us against those who stand against faith."”
What the Qur'an forbids, and to whom
The Qur'an tells of the prophet Lot, who asked his people why they approached men with desire instead of women, and left the wives Allah (﷾) had created for them. It calls this transgressing all limits. It also tells all believing men and women to guard their chastity. The rule is one for everyone: sex belongs only in marriage between a man and a woman. An unmarried man drawn to women is held to the same rule as a man drawn to men.
“We also (sent) Lut: He said to his people: "Do ye commit lewdness such as no people in creation (ever) committed before you? "For ye practise your lusts on men in preference to women: ye are indeed a people transgressing beyond bounds."”
“"Of all the creatures in the world, will ye approach males, "And leave those whom Allah has created for you to be your mates? Nay, ye are a people transgressing (all limits)!"”
“Say to the believing men that they should lower their gaze and guard their modesty: that will make for greater purity for them: And Allah is well acquainted with all that they do.”
A Muslim who sins is still a Muslim
Every Muslim sins, and none of them leaves Islam by it. The Prophet (ﷺ) said that if people did not sin, Allah (﷾) would bring a people who sin, ask His forgiveness and are forgiven. The Qur'an praises those who do wrong, then remember Allah (﷾) and ask Him to forgive them. It tells everyone who has wronged himself not to despair of Allah's (﷾) mercy. But forgiveness asks something of him. The Qur'an tells believers to turn to Allah (﷾) "with sincere repentance", and it praises those who "are never obstinate in persisting knowingly in (the wrong) they have done". Sincere repentance means real regret, stopping the sin, and trying to avoid it from then on. A Muslim who struggles with same-sex desire, and sometimes falls, is in the same place as any other Muslim struggling with a sin. He must repent sincerely and try to avoid that sin, and Allah (﷾) is ready to forgive.
Abu Hurayra reports that the Prophet (ﷺ) swore by the One in whose hand his life is: if you did not sin, Allah would take you away and bring a people who sin, then ask Allah's forgiveness, and He would forgive them.
“And those who, having done something to be ashamed of, or wronged their own souls, earnestly bring Allah to mind, and ask for forgiveness for their sins,- and who can forgive sins except Allah?- and are never obstinate in persisting knowingly in (the wrong) they have done.”
“Say: "O my Servants who have transgressed against their souls! Despair not of the Mercy of Allah: for Allah forgives all sins: for He is Oft-Forgiving, Most Merciful.”
“O ye who believe! Turn to Allah with sincere repentance: In the hope that your Lord will remove from you your ills and admit you to Gardens beneath which Rivers flow,- the Day that Allah will not permit to be humiliated the Prophet and those who believe with him. Their Light will run forward before them and by their right hands, while they say, "Our Lord! Perfect our Light for us, and grant us Forgiveness: for Thou hast power over all things."”
No one may mock or harm anyone
The Qur'an tells believers not to mock one another. The one mocked may be better than the one mocking. The Prophet (ﷺ) said a Muslim does not wrong his brother, humiliate him or look down on him. He also said Allah (﷾) does not look at faces or wealth, but at hearts and deeds. No Muslim may harm or threaten anyone. And Muslims keep the law of whatever country they live in (17:34).
“O ye who believe! Let not some men among you laugh at others: It may be that the (latter) are better than the (former): Nor let some women laugh at others: It may be that the (latter are better than the (former): Nor defame nor be sarcastic to each other, nor call each other by (offensive) nicknames: Ill-seeming is a name connoting wickedness, (to be used of one) after he has believed: And those who do not desist are (indeed) doing wrong.”
Abu Huraira reports that the Prophet (ﷺ) said: Allah does not look at your faces or your wealth, but He looks at your hearts and your deeds.
“Come not nigh to the orphan's property except to improve it, until he attains the age of full strength; and fulfil (every) engagement, for (every) engagement will be enquired into (on the Day of Reckoning).”
The Bible says the same
This is not only Islam's teaching. The Law of Moses says, "Thou shalt not lie with mankind, as with womankind". In the New Testament, Paul writes of men "leaving the natural use of the woman". Jews and Christians who hold to their scriptures are bound by the same rule.
“Thou shalt not lie with mankind, as with womankind: it is abomination.”
“For this cause God gave them up unto vile affections: for even their women did change the natural use into that which is against nature: And likewise also the men, leaving the natural use of the woman, burned in their lust one toward another; men with men working that which is unseemly, and receiving in themselves that recompence of their error which was meet.”
Perspectives
What critics say
Critics say Islam condemns gay people. Some argue that the Qur'an's story of Lot is not about same-sex relations at all.
Critics say Islam hates gay people.
Rebuttal
Islam judges deeds, not feelings: the Prophet (ﷺ) said Allah (﷾) forgives the urges people do not act on. It forbids Muslims to mock anyone, and Allah (﷾) looks at hearts and deeds. Its rule on sex outside marriage is the same for everyone.
Some argue that the sin of Lot's people was violence or cruelty to guests, not same-sex relations.
Rebuttal
The Qur'an names the act itself: "ye practise your lusts on men in preference to women". It also says "will ye approach males", leaving "those whom Allah has created for you to be your mates".
The Islamic perspective
A person who feels same-sex attraction can be a Muslim. Feelings are not sins; acts outside marriage between a man and a woman are, for everyone. A Muslim who falls must repent sincerely and try to avoid doing it again, and no one may mock or harm anyone.
The Prophet (ﷺ) spoke of the urges in people's hearts. Allah (﷾) forgives them, he said, if people do not act on them or speak of them.
The Qur'an condemns Lot's people for approaching men with desire instead of women.
A Muslim who sins remains a Muslim, and Allah (﷾), the Most Merciful, forgives those who repent sincerely.
The Qur'an forbids believers to mock one another, and the Prophet (ﷺ) said Allah (﷾) looks at hearts and deeds.