Throughout the Star Wars Prequels, Anakin gained an increased distrust in the Jedi Order. He was forced to live a whole other secret life with Padme and often felt isolated from the other Jedi around him. Even during Star Wars: The Clone Wars, Anakin admits to Ahsoka that he wanted to leave the Jedi Order for a long time. So, why didn't he?
Anakin was reluctant to join the Jedi right from the get-go. While Qui-Gon promised a better life than slavery, Anakin didn't want to leave his mother behind. And to make matters worse for the young boy, the Jedi Council openly rejected the idea of him joining the Order. But even after Anakin joined, it was an open secret that he was the Chosen One, so many would treat him differently, despite his attempts to blend in.
Things only got worse when Anakin and Padme fell in love, as Anakin felt even more disconnected from the Jedi. He knew he couldn't tell anyone in the Order, including his Master Obi-Wan, the Jedi he trusted above all others. Constantly hiding their marriage all throughout the Clone Wars undoubtedly took a toll on Anakin and likely made him question why he was even in the Order.
Anakin's problems with the Jedi continued to ramp up all the way to Star Wars: Revenge of the Sith. Around that time, his apprentice, Ahsoka, was falsely accused of murder by the Jedi. That led her to leave the Order, with Anakin even telling her, "I understand, more than you realize. I understand wanting to walk away from the Order." And shortly after, as the final nail in the coffin, the events of Revenge of the Sith showed Anakin that the Jedi had no trust in him, and he believed they were holding him back.
However, despite the Jedi Order being Anakin's entire life, no Jedi was forced to stay. Count Dooku had left the Order not long before Anakin was found, and his departure was surprisingly civil and understood by the Jedi. So, Anakin could've walked away if he really wanted to. But much to his disappointment, there was much that was preventing him from leaving.
Firstly, Anakin got told he was the so-called Chosen One. While he disliked this idea, he felt a sense of duty to fulfill this prophecy, mainly to honor Qui-Gon's death. Then the Clone Wars began, and Anakin was among the best fighters in the Order, meaning he had to help push back the Separatists. And with Ahsoka getting made his surprise apprentice, he had a lot of people who were relying on him.
The best time for Anakin to leave the Jedi would've been when Ahsoka departed. But by then, he felt the need to see the Clone Wars through to the end. As revealed in the Revenge of the Sith novelization, he and Obi-Was were viewed as the "poster boys" for the war, as the media would often follow them into battle. With representing the Jedi's fight for freedom, Anakin knew it would be difficult to walk away.
So, in the end, departing the Jedi was easier said than done. Anakin was a part of the Order for over half of his life and paired with all of his responsibilities, he thought it impossible to leave. That only further highlights the many problems of the Jedi, as the galaxy would've been far better off if Anakin was able to live out his days alone with Padme.