Gotra means clan.Say if some one's Gotra is Bharadwaj; than that means he is a descendant of sage Baradwaj.
Google defines Gotra as
In Hindu society, the term gotra (Sanskrit: गोत्र) means clan. It
broadly refers to people who are descendants in an unbroken male line
from a common male ancestor or patriline. Generally the gotra forms an
exogamous unit, with the marriage within the same gotra being
prohibited by custom, being regarded as incest.
People of different caste may have same Gotra.
Caste system is recently introduced by human society. Earlier there was Varna system.There are 4 Varnas(Brahmins, Kshatriya, Vaishya,Shudra).
Since different offspring of 1 person may belong to different varnas(although that was not very common in ancient times); it is possible that these different people of different varna , over a time got scattered and now began to be identified by different castes.
i.e say some descendants of Atri sage became Brahmins, other kshatriyas and so on over a period of time. But now we started mis-classifying these Varna systems as caste system and as it appears now that these people now belong to different castes but have same gotra.
You can read more here.