It is important that you read the Qur’an and see what it says about this so that you will not have any confusion. The Qur’an has many references on this subject. In the Qur’an Allah instructs Muslims to make peace and instructs that when a community makes peace, you cannot attack them. Yes, throughout history, people at different times have tried to interpret the Qur’an in order to justify actions which are against Allah’s instructions.
For example, in the Ottoman Empire the kings had shaykhs of Islam and they checked with them to see if their actions would be in accord with the Qur’an-i-Karim. The decisions that were made in these situations were called fatwa which means “permission given.” This worked for a while but then the Ottoman Kings began to decide what they wanted to do and they would threaten the shaykhs of Islam to give them a fatwa saying that what they wanted to do was sanctioned by the Qur’an in order to justify their own actions. Under threat of death, the counselors interpreted the Qur’an in a way that would justify the actions of the king. As a result of this, Allah took the Ottoman Empire down.
We need to pay attention to Allah’s justice, which lies in the middle of His jalal and jamal. Do not think that we are free to do anything we want. Allah will not stop you from doing something because you are free to make choices, but after you do it, you will get the consequences of your actions in this world and in the hereafter.