The reason behind this ruling is that the announcement of apostasy was not a result of matters within the bounds of personal freedom or logical conclusions. Rather, apostasy was often utilized as a sinister method to eliminate Islam and the beliefs of Muslims. Its use was as a result of political motives, not ideological or intellectual aspirations. This malicious practice on behalf of politicians, who were the enemies of Islam, could not be overlooked. As a result, Islam placed heavy penalties upon apostasy. Islam is in favor of using logical debates and discussions in order to reach definite conclusions in religious matters. If it were not for this obvious act of exploitation, this ruling would not have been enacted. In fact, freedom of thought and speech is in accordance with the essence of Islamic teachings, making it impermissible to punish anyone in pursuit of clarifying doubts and uncertainties which they may have. In regards to the jurisprudential aspect of this matter, it should be noted that laws enacted on behalf of an Islamic government are a division of jurisprudence itself, and thus not separate from the religion.
In order to shed light on this matter, it is important to keep several points in mind:
1- Islam considers the research and questioning of matters pertaining to religion – whether it be in the usul (foundations and fundamentals) or furu (branches)– as being not only acceptable but in certain aspects necessary.  Any Muslim, with respect to their level of knowledge and understanding, can question and discuss all matters pertaining to this divine religion. So long as that individual has not gained reasonable certainty, the doubts which he or she holds will not harm their status as a Muslim or remove them from the folds of Islam. 
2- From and Islamic perspective, an apostate is one who discovers the legitimacy of Islam and gains certainty in its truth, but unreasonably turns away from the religion.
God states in the Holy Quran: “Indeed those who turned their backs after the guidance had become clear to them, it was Satan who had seduced them, and he had given them [far-flung] hopes.” 
3- Groups of Kuffar (nonbelievers) who had discovered truth in Islam, in a flagrant act of jealousy, decided to use different methods to influence believers into turning away from their religion.  They hoped to reach this aim through the circulation of illogical fallacies against Islam. God ordered the believers to refrain from the use of violence against the kuffar, but to come forth with logical arguments and reasons in order to battle the propaganda they were spreading.  It is important to note that the first and primary divine order given, is for the believers to address the followers of other religions in the best of manners, unless they (the nonbelievers) are not in pursuit of the truth but rather aim to oppress and commit injustice against others. 
4- Islam was built upon a foundation impervious to the fallacies which the kuffar presented. As a result, their propaganda proved to be ineffective in defeating Islam. The enemies of Islam then chose a new method in which they aimed to display the religion as one based upon illogical and unsound reasoning. Furthermore, they hoped to exhibit Muslims as unstable followers who would join the religion, and then abandon it after some time. The kuffar decided to display themselves as people in search of the truth and would announce that they had found solace in the religion of Islam and thus, embraced it. After a short period of time, they would not only desert the religion, but heavily circulate and propagate the news of their apostasy amongst people. This method would indirectly plant seeds of doubt amongst other Muslims and make them wonder “If Islam was truly a faith based on logical reasoning, then why did these new Muslims who appeared as being scholars and seekers of truth abandon it?!”. 
Despite the fact that Islam supports freedom of religion  , considering what has been mentioned, it can be concluded that the topic of apostasy no longer lied within the bounds of personal freedom; there was no longer any relation between the two anymore. Rather, it had taken on the role of a political weapon aimed at eradicating the religion of Islam. Naturally, something needed to be done to counter this evil plan. On one hand, Islam does not want to forbid the exchange of thoughts and discussions pertaining to religion, nor does it want to force nonbelievers into acceptance of the faith. On the other hand, it wants to prevent the enemies of Islam from causing disarray amongst Muslims. Therefore, it was decided that public announcement of apostasy from the divine religion of Islam could entail heavy penalties such as capital punishment.  However, apostasy that was done in private would not bring about such punishments.
In addition to the given response, the following points should be considered:
a) It should be noted that the only form of apostasy which would entail the death penalty is when the apostate begins acting against Islam. Such acts may include slandering the Prophet (pbuh) and the Ahl al-Bayt (as) or rejecting the fundamentals of Islam. Otherwise, it is impermissible to punish someone who has doubt regarding this divine faith. An individual may even criticize or question every aspect of the usul and furu of Islam in search of answers. So long as a one does not blatantly reject the fundamental aspects of the faith and publically announce his/her apostasy, no form of punishment can be carried out upon that individual.
b) A person who becomes an apostate as a result of being presented with fallacies and misguidedly accepting them (in private and without public exhibition), will be spared from punishment. In addition, should that individual return to Islam, the good deeds they performed prior to their apostasy will be preserved. 
c) One who is seeking to change or accept a religion, should posses a certain level of logic and rationale for their actions. However, if you examine the beliefs and views of those who have left the religion of Islam for another religion or have just turned away from entirely, you will find that most of them failed to research, question, or discover any logical basis to justify their argument. You will discover that even today, public announcements of apostasy are heavily influenced by political and moral corruption, as opposed to rational arguments.
d) As previously mentioned, these punishments were primarily intended to serve as impediments for those looking to exploit the religion of Islam. Otherwise, it would not be used upon anyone who possess uncertainties regarding the faith (however strong they may be), so long as their doubts do no shift to a blatant denial of Islam. For this reason, we rarely witness the enactment of such punishments in Islamic countries.
e) It should be noted that the primary rulings in fiqh cannot be changed by any means. However, secondary rulings and those of an Islamic state (which sometimes contradict the primary ones for the benefit of the state and Muslim nation), are also a divisions of fiqh. Such rulings can be seen as an indication of the flexibility of fiqh. 
 If you refer to the beginning of the risalahs of marja’s, you will find that all marja’s say that it is necessary for all believers to have a reached a sufficient level of certainty regarding the fundamentals of their religion.
 You can refer to Question 3894 (website: 4168) in this regard.
 Muhammad Baqir Majlisi, Biharul-Anwar, vol. 97, pg. 67, hadith 15.
 Ankabut:46 “و لا تجادلوا اها الکتاب الا بالذی هی احسن الا الذین ظلموا منهم ”
 Ale-Imran:72-73 (It is good to take a look at the tafsirs on these verses).
 Baqarah:256 “لا اکراه فن الدین ”
 Muhammad ignil-Hasan Hurr Ameli, Wasa’elul-Shia, vol. 16, pp. 104-105, hadith 21099.
 Concerning the possibility of the nullification of the death penalty for apostasy, see Question 3059 (website: 3761).