Short answer
It comes from God (﷾). He placed a sense of right and wrong in every human soul when He made it. Islam calls this inborn nature the fitra. The Qur'an says God (﷾) showed the soul its wrong and its right. That is why people in every culture feel guilt. Some atheists say morality comes from evolution and society. Others say right and wrong are real facts that reason can find. Islam agrees that right and wrong are real. But evolution may explain why we feel cruelty is wrong, not why it is wrong. A society cannot judge itself by its own standard. Right and wrong bind us because the One who made us set them. Every person is answerable to God (﷾), and anyone can test a prophet's claims. The fitra gives only the broad lines, so people need a law from God (﷾) that does not bend to fashion.
Full explanation
The sense of right and wrong is placed in the soul
The Qur'an says God (﷾) gave the soul its proportion and then made known to it its wrong and its right. So the sense that there is a right and a wrong is not taught to the soul later. It was placed there when the soul was formed. Islam calls this original nature the fitra, the pattern on which God (﷾) made mankind. It carries two things: the sense of right and wrong, and the knowledge that God (﷾) is one. The Prophet (ﷺ) said every child is born upon the fitra. It is his parents who make him a Jew, a Christian or a Magian (a Zoroastrian).
“By the Soul, and the proportion and order given to it; And its enlightenment as to its wrong and its right;-”
“So set thou thy face steadily and truly to the Faith: (establish) Allah's handiwork according to the pattern on which He has made mankind: no change (let there be) in the work (wrought) by Allah: that is the standard Religion: but most among mankind understand not.”
Abu Hurayra reports that the Prophet (ﷺ) said every child is born upon the fitra (the natural disposition God gave mankind), and it is his parents who make him a Jew, a Christian or a Magian, just as an animal is born whole. Abu Hurayra then recited Qur'an 30:30.
Abu Hurayra reports that the Prophet (ﷺ) said no child is born except upon the fitra (the natural disposition God gave mankind), and it is his parents who make him a Jew, a Christian or a Magian.
Christians call it the conscience
Paul, a Christian missionary of the first century, wrote that people who never had the law of Moses still do by nature what it requires. He said its work is written in their hearts, and their conscience bears witness. Christians call this the conscience. Islam agrees. Fitra is the fuller word, because it covers the knowledge of God (﷾) as well.
“For when the Gentiles, which have not the law, do by nature the things contained in the law, these, having not the law, are a law unto themselves: Which shew the work of the law written in their hearts, their conscience also bearing witness, and their thoughts the mean while accusing or else excusing one another;)”
What research on young children has found
The hadith (a report of what the Prophet (ﷺ) said) says every child is born upon the fitra. Researchers at Oxford ran more than forty studies in twenty countries on how people naturally think about gods. They concluded that humans are naturally inclined to believe in gods and an afterlife. Justin Barrett, who co-directed the project, reports that young children tend to see the natural world as made for a purpose. That does not prove the hadith, and a Muslim needs no study to believe it. But it fits what the Prophet (ﷺ) said.
Abu Hurayra reports that the Prophet (ﷺ) said every child is born upon the fitra (the natural disposition God gave mankind), and it is his parents who make him a Jew, a Christian or a Magian, just as an animal is born whole. Abu Hurayra then recited Qur'an 30:30.
A £1.9 million University of Oxford project of more than 40 studies in 20 countries, covering both religious and non-religious societies. It concluded that human beings are naturally predisposed to believe in gods and in an afterlife.
Argues from developmental psychology that young children are naturally inclined to believe in a creator god and to see purpose in the natural world, so that religious belief arises almost inevitably from ordinary human nature.
Why humans are accountable and animals are not
People in every culture feel guilt when they do wrong: in Tibet and North America, in Siberia and South America. The Qur'an holds human beings to account, not animals. It is humans who were given the trust (amana) of reasoned, free choice. The Qur'an says God (﷾) gave people hearing, sight and understanding, showed them the way, and left them free to be grateful or ungrateful. It also says that every faculty will be questioned.
“It is He Who brought you forth from the wombs of your mothers when ye knew nothing; and He gave you hearing and sight and intelligence and affections: that ye may give thanks (to Allah).”
“We showed him the Way: whether he be grateful or ungrateful (rests on his will).”
“And pursue not that of which thou hast no knowledge; for every act of hearing, or of seeing or of (feeling in) the heart will be enquired into (on the Day of Reckoning).”
“We did indeed offer the Trust to the Heavens and the Earth and the Mountains; but they refused to undertake it, being afraid thereof: but man undertook it;- He was indeed unjust and foolish;-”
Anyone can test a prophet
The moral sense is given to everyone. So knowing good from evil does not depend on a prophet. The claims of anyone who says he is a prophet can be tested by reason and conscience, not just by his own word. Every person owes that care, because first loyalty is to God (﷾), and history has seen many false prophets. Jesus told his followers to know prophets by their fruits. The Qur'an tells those who make religious claims to bring their proof. Islam welcomes the test.
“Ye shall know them by their fruits. Do men gather grapes of thorns, or figs of thistles?”
“And they say: "None shall enter Paradise unless he be a Jew or a Christian." Those are their (vain) desires. Say: "Produce your proof if ye are truthful."”
The moral sense needs a standard
The fitra tells a person that right and wrong are real. On its own it does not reliably tell him what they are, because his time, upbringing and interests can bend it. Some atheists say the moral sense comes from evolution and from the societies we grow up in. Islam does not deny that upbringing shapes people. Evolution may explain why people feel that cruelty is wrong. It cannot show that cruelty truly is wrong, or that we must avoid it when it pays. And a standard that each generation sets for itself cannot judge that generation. Others, called moral realists, say right and wrong are real facts that reason can find, whatever any age believes. Islam agrees that they are real and do not depend on the age. It asks why they bind us, and answers that the One who made us set them. Reason alone has not settled the details, since sincere people have reached opposite answers, as the history of interest below shows. So God (﷾), who gave the moral sense, also gives the standard it answers to. His commands are not arbitrary: they come from His wisdom, and the Qur'an says Allah (﷾) never commands what is shameful. The Qur'an commands justice, doing good and generosity to relatives, and forbids shameful deeds and injustice. The medieval Church condemned lending at interest as a sin. The Council of Vienne ordered that anyone who obstinately insisted it was not a sin be punished as a heretic. The same lands now run on interest. The Qur'an forbade usury (lending at interest) in the seventh century and forbids it still.
“Allah commands justice, the doing of good, and liberality to kith and kin, and He forbids all shameful deeds, and injustice and rebellion: He instructs you, that ye may receive admonition.”
“When they do aught that is shameful, they say: "We found our fathers doing so"; and "Allah commanded us thus": Say: "Nay, Allah never commands what is shameful: do ye say of Allah what ye know not?"”
The council decrees that anyone who obstinately maintains that practising usury is not a sin is to be punished as a heretic.
Rules that in a loan of money or other goods it is not in itself unlawful to agree on the rate of profit allowed by civil law, unless it is plainly excessive.
“Those who devour usury will not stand except as stand one whom the Evil one by his touch Hath driven to madness. That is because they say: "Trade is like usury," but Allah hath permitted trade and forbidden usury. Those who after receiving direction from their Lord, desist, shall be pardoned for the past; their case is for Allah (to judge); but those who repeat (The offence) are companions of the Fire: They will abide therein (for ever).”
Perspectives
Morality comes from evolution and feeling
Many atheists say our sense of right and wrong comes from evolution and human feeling. It helped our ancestors survive, they say, and there are no moral facts beyond us.
Evolution shaped our moral judgements to help our ancestors survive, not to track moral truths.
Rebuttal
Street draws the conclusion herself: if moral truths exist, any match between them and our beliefs would be a coincidence. Then the conviction that cruelty is wrong is only a survival habit. Yet hardly anyone lives as if the wrong done to them were only that. The Qur'an gives the reason the moral sense can be trusted: God (﷾) made known to the soul its wrong and its right.
There are no objective values: they would be strange things, unlike anything else in the world.
Rebuttal
They are strange only in a world of matter alone. Hume saw that an "ought" cannot simply be drawn from an "is", and matter and genes give only what is. Mackie grants that ordinary moral judgement takes values to be real, so on his view every such judgement is in error. If the world has a Maker who commands justice and doing good, real values are what we should expect.
Christian
God has written the work of His law on every human heart, and the conscience bears witness to it.
Paul writes that Gentiles without the law show its work written in their hearts, their conscience bearing witness.
Rebuttal
Islam agrees that the moral law is written in every heart (Qur'an 91:7-8). Islam adds two things: the same fitra holds the knowledge that God (﷾) is one, and the moral sense needs a standard from God (﷾).
The Islamic perspective
The sense of right and wrong is part of the fitra, the nature God (﷾) gave every human being, as the Prophet (ﷺ) taught. It makes everyone accountable, and it lets anyone test a prophet's claims. But it needs revelation to supply the standard.
The Qur'an states that when God (﷾) formed the soul, He made known to it its wrong and its right.
The Prophet Muhammad (ﷺ) said every child is born upon the fitra, the natural way. It is the parents who make him a Jew, a Christian or a Magian.
The fitra carries both the sense of right and wrong and the knowledge that God (﷾) is one.
Because every person has the moral sense and the power to choose, every person is accountable to God (﷾).
The moral sense does not depend on a prophet. So a man who claims to be a prophet can be tested by reason and conscience.
A moral standard set by each generation cannot judge that generation, so the standard must come from God (﷾).
The Qur'an's law does not bend to the age. It forbade usury in the seventh century and forbids it still. The Catholic Church once ruled that those who defended usury be punished as heretics. It now allows lending at interest, unless it is plainly excessive.