“Indeed the number of months with Allah is twelve (lunar) months in the register of Allah (from) the day He created the heavens and the earth; of these, four are sacred.” (Quran 9:36).
Allah mentions them as a whole in the Quran but He doesn’t mention them individually so we must look at the hadith to understand more. “three of them are in succession: Dhul-Qa’dah, Dhu Al-Hijjah, Al Muharram and Rajab of Mudar.” Al-Bukhari.
The reason the first three are sacred are because people will travel to Hajj, perform Hajj and go back home from Hajj. Rajab is sacred because people can they perform Ummrah. Fighting is prohibited in there sacred four months.