I've never taken a medal.
I don't think they are exclusively to trail races. I've been offered some at road races as I passed through the line.
I think they tend to come from either professional race organisers or charity events.
T Shirts I see differently. They are partly a promotion for the race. We always handed out a free Ribble Valley 10K shirt and I've seen them on folk overseas. They were usually included in the entry fee although I sometimes bought shirts, such as at the Three Peaks if they were decent quality.