The only way we can determine its gender is from the context.This is not difficult, since we never come across an isolated phrase with a pronoun, without any other surrounding phrases. This is the function of the pronouns: They are used only in case that we don't want to repeat a noun already mentioned in the previous sentence.
An example from modern Greek:
Να ο Γιάννης. Τα βιβλία του είναι στην τσάντα. ( = Here is John. His books are in the bag)
Nα το μπουκάλι. Το καπάκι του είναι στο τραπέζι. ( = Here is the bοttle. It's top is on the table.)
The first του is masculine, which we can figure out from the previous sentence. ("Ο Γιάννης" to whom it refers is masculine)
The second του is neutral, because "το κουτί" to which it refers is neutral.
(and something else that I noticed: In the phrase "ἀπεκρίθη Θωμᾶς καὶ εἶπεν αὐτῷ"( = Thomas answered and told him) the word "αὐτῷ" is only Personal pronoun,dative masculine third-person singular and not Personal/Possessive pronoun etc.)
---------------------------------------------------------------------------------------------------------------------------
Vasiliki Baskou, Instructor/Director, https://learn-greek-online.com.