As someone at the tail end of this, I don’t believe men drove women out as much as women self-selected out for mainframe computing, which slowly became obsolete. You are correct, until the end, mainframe computing was a female dominated field. Mainframe computing offered a better work / life balance and better benefits, due to the fact it was often governmental or large business oriented, and due to socioeconomical reasons attracted females away from microcomputer programming.
Programming and maintaining COBOL is a wildly different skillset than 80’s and early 90’s computing, and mainframe programmers just left computer programming rather than relearn their craft.
This had the effect of making microcomputing very male dominated, but I think this was as much of a choice of females as of males.