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.
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.