Amina Inloes, Amina Inloes is originally from the US and has a PhD in Islamic Studies from the University of Exeter on Shi'a hadith. She is the program leader for the MA Islamic Studies program at the... Answered 3 months ago

Generally, this understanding is taken from what has been narrated about the revelation of a surah or ayat. 

However, sometimes there are contextual clues. For instance, if a verse discusses a historical event that happened after the hijrah, such as the Battle of Badr, it is understood that it was revealed in Medina.

Also, the style and content of Meccan verses are somewhat different from the style and content of Medinan verses. The Meccan verses tend to be shorter and focus more on the existence of God, the afterlife, and important ethical points, whereas the Medinan verses tend to be longer and also discuss matters such as legislation. This isn't an absolute rule but also lends some evidence.