The Office of Foreign Assets Control (OFAC) is a financial intelligence and enforcement agency of the United States Treasury Department. It administers and enforces economic and trade sanctions in support of U.S. national security and foreign policy objectives.
I wonder how many civil actions, in full comfort and safety of your democratic country, you took part in, and what was the result of it.
Various tools hosted on Github can be considered dual-use (i.e. AES/TLS libraries). Furthermore, Microsoft was made to apply sanctions against Karim Khan of the ICC for his involvement in investigating the genocide of Palestinians; I doubt Microsoft would be granted an exception so they can serve Hamas' greatest supporter after that.
I don't know if Microsoft has applied for any exceptions, but even if they did, I doubt they'd be able to get them. That's on top of the probability of bad publicity ("Microsoft wants to cut deal with Iran") and the lack of incentive you mentioned.
"greatest"? Hardly. A charge was brought before the ICC from South Africa which required the ICC to investigate.
There are much bigger supporters of Hamas, the sanctions against employees of the ICC is just the current US government flexing its retribution muscles.
You are mixing up ICC and ICJ. South Africa brought a case to the ICJ. This is the country equivalent of suing another country so its not really forcing ICJ to investigate so much as south africa is presenting a case which icj will decide on (eventually anyways, icj is famous for being slow).
The ICC on the other hand makes its own decisions on who to investigate/charge. Countries can file referrals to it, but the ICC prosecutor has discretion on what they want to investigate and pursue.
[Anyone who thinks the ICC likes hamas should remember that the icc also filed charges against a hamas leader too. Its difficult for them to investigate hamas because they are only allowed to charge people who are currently alive]
There are blanket sanction waivers (General License) by OFAC to allow certain things. There's also the possibility to get an OFAC license (as GitHub did.)
The real issue is there is little to no advantage (realistically no money to be gained from Iran) or even awareness (sometimes the cloud infrastructure bans Iran by default and you don't have enough users to even know that's the case to care.) The legal counsels would generally be conservative and advise against it; there needs to be someone from the business side, e.g. a product manager that cares enough to try to push back on the legal. There often is not or it is hard to justify the tiniest risk, hence you block.