Arrange SQL Server rows in a paired sequence
You can use this ORDER BY:

SELECT  ...
FROM ...
ORDER BY
    CASE checkpoint WHEN 'A' THEN id 
                    WHEN 'B' THEN related_id
    END,
    checkpoint ;