No, unfortunately, there is no way to put a test inside of a set expression (with one exception, but the easy answer first):
Create either and invisible mission or a cron that does the following:
If (HasShipX and Male and noPenis)
Grant Penis
This will work fine, maybe make it when you sell the ship, remove the outfit (regardless of gender. If they dont have it, nothing will happen).
The other method is rather a bit fancier, less entertaining, and probably less usefull in the general case.
This hinges around the fact that there IS indeed a way to have a set expression evaluate a 'test'. This hinges around the Axxx/Fxxx operators. IF mission xxx is active, abort it. So at the beginning of the game, start invisible missions XX and XY. In mission XX's onfail, put SXX, plus everything you want to have happen when the gender is evaluated (note all of these will happen every time you do this, regardless), and the same thing for XY. So, every time you want to evaluate the pilots gender, put FXX FXY. The missions will reactivate themselves and also do whatever is in the onfail field (or onaccept).
Note that the missions should be invisible and should also have the CanAbort flag set. If they do not have the latter, then the failed mission will remain (and it would have a bullet in front of it if it werent invisible, and show the failtext when you reach the destination, but there shouldnt be one, or the player will 'accieve' his/her gender.)
Anyway. The first method will work for you. The second is a special case if you need something to happen midflight. There are ways to set up more than one of each in such a way that you dont have everything happen at once, but this is really a very advanced discussion that Im fairly sure no plugin will ever take advantage of.