The legislation setting out the testing rules is
https://www.legislation.gov.uk/uksi/...ulation/6/made
I think the main bits are:
6.—(1) This regulation applies to a person (“P”) specified in paragraph (1) of regulation 5 (requirements relating to tests) who—
(a)intends to remain in England for two days or more after the day of their arrival; or
(b)intended to remain in England for less than two days after the day of their arrival but in fact remains in England for two days or more.
12 (c)“testing package” means—
(i)where P is a person falling within regulation 5(1)(a) (arrivals from category 1 countries or territories), a booking for a day 2 test,
(ii)where P is a person falling within regulation 5(1)(b) to (e) (arrivals from category 2 and 3 coutnries or territories) and—
(aa)intends to remain in England for 8 days or more, a booking for a day 2 test and a day 8 test,
(bb)intends to leave England on or before the 7th day after P’s arrival in England, a booking for a day 2 test.
It does mention "2 or more days" as the cut-off, so I think a next day transit is exempted, but a 2 night transit still needs to buy a day-2 testing package (but not a 2+8 as you leave on/before the 7th day)