Venezuela did a lot of things to restrict the use of the US dollar including forcibly converting all USD accounts at their banks to their own currency at an unfavourable ratio.
They are doing it illegally. My point still stands.
Generally it’s only illegal in countries which have unstable currencies and strict capital controls.