Battleships were built to engage at range. Even at that time, the rangefinding gear was fairly extensive. Concerning the HMS Barham, one of the ships in the engagement:
Barham was completed with two fire-control directors fitted with
15-foot (4.6 m) rangefinders. One was mounted above the conning tower,
protected by an armoured hood, and the other was in the spotting top
above the tripod foremast. Each turret was also fitted with a 15-foot
rangefinder.
And from the picture you can get a good idea of the height of the conning tower above decks:

For scale note the row of sailors on deck. From the rangefinders position on top of the conning tower, the visible horizon is much farther away. Scaling the diagram found on the Wikipedia page, gives a rough estimate of 120ft above the waterline. Using the formula provided here, (if my math works out), I get a range of 21.6 km, or over 23,000 yds for a minimum range. As pointed out in the comments, the other ships superstructures will project well above the waterline as well, so the actual maximum range you could visually detect another ship would vary by circumstance including the conditions and the height of the structures on the opponent vessals..