Jehosheba was likely born to Jehoram by a wife other than Athaliah, making her Ahaziah’s half-sister (see Josephus, Antiquities 9.7.1).
The infant Joash was born to Zibiah of Beersheba (2 Chronicles 24:1), possibly a lesser-known wife of Ahaziah. This might have allowed the baby's birth to go unnoticed by Athaliah.