What is the apostrophe for in o'clock?

An apostrophe "stands in" for missing letters in a contraction.

o'clock is a contraction of "of the clock" and the apostrophe indicates the missing letters.