I've never fully tested it but from casual observation, it appears to be based on a 15-minute interval (if I'm remembering correctly).
So, if I text you right now (12:30 PM my time) and we text back and forth without really any breaks, a time stamp would appear above whoever sends the first text at or after 12:45 PM...I think...