Female officers in the US military are addressed as ma'am
, not sir. I was actually in the military, and I can tell you... calling a female officer "sir" is a bad
idea. It gets you in trouble.
Starfleet was based on the US Navy, so it is perfectly appropriate for female Starfleet officers to be addressed as ma'am.
I won't go into the "but Starfleet isn't military" debate because that's pointless.