The top rail closes off the top of a gate frame and gives the tops of the battens or slats something solid to fix into. It usually uses the same tube as the side bars (the stiles), cut at an angle and joined at each corner so the frame looks like one clean outline.
On battened or slatted gates the top rail is often hidden behind the infill. On open-look gates (loop tops, spear tops, picket-style runs) the top rail is part of the visible composition and often gets a heavier or differently-profiled section to feature it.
For pool-compliant gates, anything fixed to the top of the rail (decorative ball caps, finials, fittings) needs to fall outside the AS1926.1 non-climbable zone or be eliminated entirely so a kid can't grab and climb.