I would be very thankful if you could answer me on my following question. In Quran is written: "There shall be no compulsion in [acceptance of] the religion. The right course has become clear from the wrong. So whoever disbelieves in Taghut and believes in Allah has grasped the most trustworthy handhold with no break in it. And Allah is Hearing and Knowing."
But also on other places is talked about punishing or killing people who do things like for example: stopping being Muslim, having sex before marriage, being gay and so on. With punishing I mean punishing on this world, and not when we die. If we have freedom to be Muslims or not, why there is no freedom of doing some things that are against religion but don't hurt other people. I am really confused and i hope you can clear this topic for me. Thank you in advance.
Regarding the issue of religious freedom, you are right that the Quran guarantees it. The scholars, however, had to also reconcile various hadith narrations in which the Prophet Muhammad
is mentioned as putting limitations on religious freedom. Another case is that of Abu Bakr in the Riddah wars; when some Arabian tribes wanted to leave Islam and stop paying the zakat, Abu Bakr did not let them but fought them until they were one again part of the Islamic state.
Out of these historical anecdotes, the scholars tried to come up with an interpretation of the religious freedom mentioned in the Quran. The interpretation they came up with was that Islam should not be forced on others, but that a Muslim should not be allowed to leave Islam. From their position of power and authority, it seemed only natural that this should be the case. Islam is God’s chosen religion, so people should be prevented from leaving it for their own good if not for anyone else’s.
That way of thinking went unchallenged until the last century or so. The new reality that Muslims found themselves in (being in a position of weakness rather than strength) forced the scholars to re-examine their interpretation of the idea of religious freedom. In the 20th century there was also a new movement to take the Quran more seriously than before. In the past, the Quran was treated as just a piece of historical evidence that stood side-by-side with hadith. In the 20th century, various new thinkers (Mustafa Mahmud, Muhammad al-Ghazali, Sayyid Qutb, Said Nursi, Ahmad Moftizadeh) arose who rejected this way of thinking and considered the Quran’s teachings superior and more authoritative than hadith. And with this came a new interpretation of various issues within Islam.
Out of this atmosphere came people like Mahmud Shaltut (Grand Imam of Al-Azhar from 1958 to 1963) ruled that apostates are only punished if they try to fight the Muslims and plot against them, that mere apostasy is not punishable, and more recently Ali Gomaa (Grand Mufti of Egypt from 2003–2013), who also says that apostasy is not punishable in Islam unless the apostates try to make other Muslims leave Islam. While this is not perfect religious freedom and not perfect freedom of speech, it is an important step in the right direction. Many clerics have yet to update their thinking on this matter, but that might happen within the next 50 years.
Regarding the death penalty for things like adultery and homosexual sex, this too, like the issue of apostasy, went unchallenged until the 20th century. The Egyptian scholar Muhammad Abu Zahra, one of the greatest scholars of Islamic law in the 20th century, rejected execution of adulterers saying that the historical evidence could be interpreted in a different way. Abu Zahra is not a liberal modernist, he was one of the religious scholars (ulema), and his opinion is highly significant. Please see: Professor Abu Zahra: The Egyptian Islamic Scholar who Rejected the Punishment of Stoning
Ideally, there should be a constitutional law that all Muslims and non-Muslims follow (as in Malaysia, although the Malaysian system has serious issues). Islamic law would be something that all Muslims willingly choose to live under, and anyone who wants to leave Islam should have the right to do so, so that they stop being subject to Islamic law and will only be subject to constitutional law that Muslims and non-Muslims agree upon.
In summary, the things you mentioned (killing apostates, adulterers and homosexuals) are all issues that have already been solved by respected scholars. What remains is for the rest of the scholars and preachers to catch up.

On what basis do you claim that Muslims should simply be able to opt out of religious law in an Islamic state? If anyone who is found/suspected of a crime can just say they renounce Islam to avoid the hadd punishment (zina/liwat, theft etc.) then it completely takes away the threat of those punishments as deterrents of crime (punishments which already have strict conditions and are rarely enforced by design). Also there is the punishment for hirabah found in the Quran which, as far as I understand, is meant to apply to non-Muslims too. It is one thing for an individual to lack belief in Islam in their heart and not follow Allah’s commands, but to create a system where people can just renounce Islamic law at will belittles and subverts the foundations of a sharia-administered territory, as does ignoring apostates publicly calling people to abandon Islam and thereby threatening the state. Do you have any evidence that the prophet SAWS practiced or endorsed such a system?
Leaving Islam should require official steps, with important considerations like the loss of benefits associated with being Muslim. And, for example, the status change should only take place if there are no legal proceedings against the person. In this way the system cannot be abused in order to avoid legal punishments.
As for allowing people to renounce Islam, or ignoring apostates publicly calling people to abandon Islam: the legal system can function on the basis of assuming that such people are acting in good faith, and meaning no harm or damage to Muslims, or to society. And if it is found that they are not acting in good faith, steps can be taken against them.
This requires a jury-based legal system where the representatives of the law are empowered to act based on their own wisdom and conscience, as opposed to being restricted by narrow legal codes. And this is the kind of legal system I believe in. In this way apostates would be required to not behave in antisocial ways and they would not be able to find legal loopholes to bypass the will of society.
So if the objection is that *some* apostates may require special treatment, a jury-based legal system can give them that special treatment.
When it comes to deciding what kind of system the Prophet PBUH would have created or endorsed, due to the nature of evidence we have, it is not possible to build any fully-fleshed-out system from the Quran and hadith. We can only decide whether a certain set of proposals conflict with the evidence we have, or do not conflict with them.
I believe Islam leaves most of the workings of legal systems and systems of governance blank in order to let each society have its own ways of functioning that are suitable for it, and that can improve with time and experience. Islam can provide the basic framework of thought for such a society, but the details are worked out by such things as social tradition and experience, recent history, relationships and status in comparison to neighbors, and so on.
My comment disappeared
Sorry, the caching system must have continued to show the older version of the page after you left your comment.