Don't be too hard on yourself
Reflexively correcting your DM is not great, but being aware of it and trying to improve is great! Even if your progress isn't as rapid as you'd like, making the effort is the greater part of success.
This is a two part problem: you are one part, and your DM is the other
The other players are non-factors, as they apparently don't care about the rulings. So the main issues come down to (1) your DM being forgetful (or inattentive or inconsistent), which is the source of the errors you notice, and (2) your self-described inability to not point out those errors. So we can attack the issue from either or both points.
Help the DM become more consistent
From the description it sounds like the DM is relatively inexperienced (at least with D&D 5e), and simply forgets which rules apply and when. That's pretty common, but you can't force anyone to study the rules in depth if they aren't motivated to do so. What I recommend is helping the DM prepare some kind of reference notes to address areas where you notice regular mistakes. The format doesn't matter very much as long as it's helpful to the DM. Having an at-a-glance reference not only provides the mechanical information needed but also helps reinforce a habit of checking specific information out quickly before committing to a ruling.
That's what I do for rules that I know I forget or make mistakes with often. Many DM screens are great for this, as they include a quick reference for most of the base mechanics of the game. For more specific references (like the properties of a homebrewed item) I like to prepare index cards with the relevant information. I won't need it as much as the information on the DM screen, but it's still available at a glance when needed. And if the DM finds themselves with too many index cards to work with for a session, then they've planned a session beyond their ability to keep organized and have a chance to pare things back.
The DM is likely to improve with experience, both in running any TTRPG as well as with the specific mechanics of D&D 5e. This is a device to help them gain that experience more quickly, while also mitigating the impact of inexperience while it's a factor. It's also worth mentioning to the DM that the inconsistency in rulings is a problem for you, and brainstorm with the DM about why it's coming up and what steps you might be able to take, together or separately, to make things better in the future.
Understand why you feel compelled to interrupt, and recognize that this is bad form at a gaming table
First and foremost: it is inappropriate in most games to contradict the DM in the moment. Even if you are correct about the rules, the DM is responsible for keeping the game running (in addition to knowing, understanding, and correctly applying the rules). Fixing rule-based errors while slowing the game and distracting player focus is not necessarily better than the game progressing fluidly with a more fluid approach to the rules. Feel free to consider it a rule that you not contradict the DM in-game, and then bring your enthusiasm for strict rules adherence into play.
It may also be worth reminding yourself what the role of the DM is at the table. It's not just a matter of knowing the rules and applying them exactly. The DM's job is to interpret the rules, what they are meant to represent, and how the current in-game environment interacts with them. I tweak the rules all the time to better suit specific circumstances in an encounter, though I'm generally careful to explain my reasoning for not using the official rule. The DM not only applies rules, they also determine which rules apply and when.
As for how, exactly, you might restrain yourself, I'll ask about how you managed to stop correcting the other players. The question states that you realized that correcting the other players wasn't your responsibility and so you stopped. Similarly, it isn't your responsibility to run the game for the DM, and it isn't clear to me why that realization worked in the one case but not the other-- particularly when you've observed that this behavior degrades the game for everyone. It's hard to give specific advice when this is unclear, but I can suggest a couple of very broad options which might help you with your side of the issue:
Mention relevant mechanics where appropriate. I sometimes do this myself as a player, mostly to remind myself of the rules in the moment and to give the GM (or other players) a chance to correct me. If you roll a natural 20 on an attack roll, it's easy to say "Yes, a critical hit! Now I get double damage dice!". Bringing up the mechanical result as a comment is not correcting anyone, nor is it rules-lawyering.
Be the DM. This combines thorough knowledge of the rules and a propensity for correcting others with the actual responsibility for doing so in the game. There are other factors governing how well this will work (like the rest of the group buying in), so it may not be a workable option for you.
Write down inconsistencies you notice during sessions and commit to talking about them after sessions. You can still note the issues, and won't forget about them, but by moving the discussion of problems to a different setting you may be able to deflect the urge to force a conversation at the time the disputed ruling occurs. This is what I do as a DM. I make my ruling and stick to it, but I write down the item in dispute, promise to look it up after the session, and then at the next session update people on what I've found and fix any problems the mistake may have caused (like giving a free potion of healing to a player who lost HP due to the error).
Play a different game. D&D is a relatively rules-rigid system, compared to many others that exist. If strict adherence to the rules is causing problems at your table, playing a game where the rules are less strict might help. That said, if you really like sharply defined rules you may not enjoy a game system that's looser with them.
Appreciate what matters in the game. Some issues are more consequential than others. Inconsistent rulings on things like critical hit damage may be irritating (I would probably be annoyed), but it doesn't really matter when it wouldn't change what choices you make. You would probably not choose to not land a critical hit (even if that were an option available to you, which it usually isn't) with double-dice-plus-modifier versus max-dice-plus-roll. Stating the wrong duration of Shield isn't very important if there aren't additional attack rolls to resolve. It might be worth stopping to consider whether or not a mistaken ruling is consequential, at all. If nothing else that time to think it over might help break the "I can't stop myself" cycle.