So to my understanding national security is one of the utmost responsibilities of a head of government. However, how its foreign policy is done is another. My question is if a head of government saw their commitments as a UN member nation being a threat to their national security could they limit their role in those commitments or completely void them? Would it be illegal to limit or completely void their role in those commitments as a member nation (in the case of international law)?
Member countries ignore the UN all the time. While it may be a violation of international law, this means little in the absence of any power of enforcement, and the UN has very little ability to compel its member states to do anything.
Taking a simple example, UN member states often do not meet their full financial commitment to the organisation. As of 2014, members collectively owed the UN $3.5 billion, and about $2.6 billion to the separate UN peacekeeping budget.
This may occur for various reasons:
Technical delays in payment, due to different fiscal rules;
Withholding money in a deliberate attempt to influence UN policy;
Simply feeling the money could be better used elsewhere.
Regardless of the motivation, these countries felt their UN obligations were in conflict with national wellbeing (and security in the broadest sense), and chose to disregard the UN.
There are also many cases of governments refusing to implement UN resolutions. A long-standing example is UN Security Council Resolution 242, which calls upon Israel to withdraw from territory occupied in the Six Day War in 1967. Fifty years later, the Israeli government has no intention of withdrawing from these territories. Again, if the demands of national security are perceived to conflict with UN obligations, national security invariably wins.