Yes, switching genders can happen in various lifetimes. Example, from the Therigatha:
3.1 6.6. Mahāpajāpati Gotamī
6 Mahāpajāpatigotamītherīgāthā
4.1 Oh Buddha, my hero: homage to you! Buddha vīra namo tyatthu,
4.2 Supreme among all beings, sabbasattānamuttama;
4.3 who released me from suffering,
Yo maṃ dukkhā pamocesi,
4.4 and many other beings as well. aññañca bahukaṃ janaṃ.
5.1 All suffering is fully understood; Sabbadukkhaṃ pariññātaṃ,
5.2 craving—its cause—is dried up; Hetutaṇhā visositā;
5.3 the eightfold path has been developed; Bhāvito aṭṭhaṅgiko maggo,
5.4 and cessation has been realized by me. Nirodho phusito mayā.
6.1 Previously I was a mother, a son, Mātā putto pitā bhātā,
6.2 a father, a brother, and a grandmother. ayyakā ca pure ahuṃ;
6.3 Failing to grasp the true nature of things, Yathābhuccamajānantī,
6.4 I’ve transmigrated without reward. saṃsariṃhaṃ anibbisaṃ.
7.1 Since I have seen the Blessed One, Diṭṭho hi me so bhagavā,
7.2 this bag of bones is my last. antimoyaṃ samussayo;
7.3 Transmigration through births is finished, Vikkhīṇo jātisaṃsāro,
7.4 now there are no more future lives. natthi dāni punabbhavo.
8.1 I see the disciples in harmony, Āraddhavīriye pahitatte,
8.2 energetic and resolute, Niccaṃ daḷhaparakkame;
8.3 always staunchly vigorous— Samagge sāvake passe,
8.4 this is homage to the Buddhas! Esā buddhāna vandanā.
9.1 It was truly for the benefit of many Bahūnaṃ vata atthāya,
9.2 that Māyā gave birth to Gotama. Māyā janayi gotamaṃ;
9.3 He swept away the mass of suffering Byādhimaraṇatunnānaṃ,
9.4 for those stricken by sickness and death. Dukkhakkhandhaṃ byapānudī”ti.
…Mahāpajāpatigotamī therī ….
[Minor edits for clarity]