Note: there is significant disagreement about whether Thanos actually wields Mjolnir and Stormbreaker. If he doesn't, no further explanation is required. For the purposes of this answer, I'll assume that he does and attempt to explain how this could be possible.
The criteria for wielding Mjolnir and Stormbreaker aren't clear.
At the beginning of Thor (2011) Odin places this enchantment on Mjolnir:
Whosoever holds this hammer, if he be worthy, shall possess the power
Unfortunately, Odin doesn't provide us with a handy guide of what "worthiness" means to him. Even after Thor becomes worthy at the end of Thor, he isn't exactly a paragon of good behavior. He's "heroic" in that he generally tries to do good, but he can also be arrogant1 and irresponsible2. The same descriptors apply to Tony, who can't wield the hammer. Neither can Rhodes, Barton, or Banner.
Option 1: Thanos is worthy
In an excellent answer to a related question, A J proposes that the worthiness comes from "being willing to sacrifice [oneself] to protect others." This isn't a airtight explanation3. Based on this criteria, Thanos might actually be worthy. At the beginning of Avengers: Endgame, he...
...destroys the stones because they are a temptation. Specifically, they are a temptation to the Avengers to destroy the new way of life that he has inflicted on the universe. The effort of doing this nearly kills him.
His logic is twisted, but his intentions are genuine. He believes he is protecting others from a grave threat, and he is willing to sacrifice himself to achieve this protection. It's possible that Mjolnir finds him worthy based on these criteria.
Option 2: Thanos is powerful
Thanos has been claimed to be "the most powerful being in the universe." It's not clear that this is literally true, but he is a remarkably powerful being able to do things that no one else can. We also know that Odin's magic isn't unbreakable: Hela is able to escape his imprisonment. This is speculation, but there's nothing logically inconsistent about Thanos being able to break or ignore Odin's spell.
1 "Strongest. Avenger." (Thor, Thor: Ragnarok)
2 "You were supposed to protect us. Asgard was supposed to protect us!" (Eitri, Avengers: Infinity War)
3 Just by being part of the Avengers, Barton and Rhodes risk their lives to help others. It's part of the job description. Futhermore, in Endgame, we see that...
...Barton is willing to sacrifice his life to get the Soul Stone.