One way they do it is by having traffic cams just past the on ramp of the highway, which takes your picture
Then there's another one 6 miles down the road, which takes your picture again, compares the timestamp with the picture of the first camera, and calculates your average speed over those 6 miles