In the case of military planes, they could try convincing someone with parts to secretly violate the UN sanctions, which may not be difficult if they have something the other really wants, like cheap oil.
If nobody has parts or those who do can’t be bribed, such as the case of Iran’s F14s, then you cannibalize planes until you run out of critical parts, and then the entire fleet is grounded. That is, after all, the goal of the sanctions.
However, for civilian planes, like North Korea’s state-owned airline, there is a humanitarian exception to the sanctions to keep their planes airworthy—mostly so they don’t crash and kill innocent people on the ground in other countries.
Keep in mind that sanctions apply to anyone doing business with that country, even outside of its borders. They can’t just fly their planes somewhere else for maintenance to get around the sanctions.