Generally speaking, it's not allowed. The supply chain has a very long tail and there are all kinds of steps and contracts that are based on the destination specified when goods are first loaded on a ship. Unloading at a completely different port far away would be a nightmare. As for why ships aren't utilizing other ports more, see [1].
[1] https://www.wsj.com/articles/why-container-ships-cant-sail-a...