Relevant RAM addresses
AddressExplanation
0x0F69ACY-coordinate of kart (floating point)
0x163450Y-coordinate as of previous frame (floating point)
0x18CA90Your time for lap 1 (integer)
0x18CA94Your time for lap 2 (integer)
0x18CA98Your time for lap 3 (integer)
0x18CA84The time when you finished lap 1 (integer)
0x18CA88The time when you finished lap 2 (integer)

Computing the time at which you cross the finish line
In some frame, your kart crosses the finish line. Your kart's y-coordinates (the component that changes as you move perpendicular to the finishing plane) from the current frame and previous frame are used to compute a more precise estimate of when your kart crossed the line. Example :

Y=21       (new position)
Y=20 -------- Finishing Line ------
Y=17       (previous position)

The game assumes you have a constant speed over the duration of the frame, so it says you crossed the line 3/4 of the way through the frame. So it will subtract 1/4 of a frame (0.25 * (1/60) seconds in NTSC) from the current internal timer (which is a floating point number, different from what you see on the on-screen display) and save that as the time when you completed the lap.
Some code from the ROM which does the calculation
Example values in parenthesis:
80009258 : Start of function
8000925C : Move A2 to F14 (-212.2321) (current position)
80009260 : Load F12 from 0x8016344C (-210.0) (finish line)
80009268 : Move A1 to F4 (-209.206) (old position)
8000926C : F2=F12-F14 (2.232101)
80009274 : Load F6 from 0x800ECFA4 (0.01666666)
80009278 : F16 = F4-F12 (0.7939606)
80009280 : F8 = F6*F2 (0.03720168)
80009284 : Load F4 from 800DC598 (144.2922) (race timer)
80009288 : F10 = F2+F16 (3.026062)
80009290 : F18=F8/F10 (0.01229376)
80009294 : Store F4-F18 in F0 (144.27999)

Converting to the displayed lap time
The output from the previous calculation was a floating point number (144.27999 seconds in the example). That value is then multiplied by 100 (14427.999), and then rounded down to a whole number (14427). Your lap time would then be saved as 144.27 seconds. Some code from the ROM which does the calculation
8005CC0C : Load F10 from 0x8015F898 (value from previous calculation)
8005CC18 : Multiply F10 by F0 (100.0) into F16
8005CC24 : Truncate F16 into F18
8005CC28 : Copy F18 to V0
8005CC30 : Store V0 at 0x0010(s0)
8005CC50 : Load 0x0010(s0) into T4
8005CC5C : Store T4 at 8018CA90

Laps 2 and 3
The times (truncated to integer hundredths) when you finish lap 1 and 2 are stored in memory. These are then subtracted to produce your lap time for lap 2. The same quality lap may be given a different time (off by 0.01) depending on what the more precise decimal places of the timer were when you started the lap. The variations in the rate at which the race timer increments itself will also impact the lap time.
Some code from the ROM which does the calculation
8005CC68 : Load 8018CA88 into T2
8005CC6C : Load 8018CA84 into T3
8005CC70 : T5 = T2-T3
8005CC74 : Store T5 at 8018CA94