An 18-year-old man has died after he left an ambulance and was hit by a car on the M5 motorway, police have said.