Why was Joseph allowed to imprison Shimon? That seems to transgress theft (both the Ten Commandments and/or the Noahide laws)?
Disclaimer: as I said many times before, ruling pre-Matan Tora people with post Matan Tora rules is wrong.
That being said, what Yossef did wasn't transgress theft
רמב"ם הלכות גנבה פרק ט הלכה ב
אין הגנב חייב עד...וישתמש בו וימכרנו לאחרים ...
Rambam Rules of theft 9:2
The kiddnapper is not considered kidnapper until... He [the kidnapper] will enslave him [the kiddnapped], and will sell him...
Shimon wasn't enslaved nor sold.
This falls into the category of pikuach nefesh and dina demalchuta. Certainly any Beit Din lacking the power of prophecy would agree with Joseph that 10 sons of a foreign prince like Jacob, coming in by separate entrances (according to Breshit Rabbah) are suspicious enough to justify detention. Shimon and Levi were known to have destroyed Shechem by themselves, which would be ample reason to separate them (as Tanchuma says).
If we assume the Beit Din knew that they were Joseph's brothers, it still makes no difference. According to all evidence known at the time, Joseph's brothers hated him and wanted to kill him. Joseph was the Prime Minister who saved Egypt and the whole world from famine, and any threat to him was a matter of national security for Egypt. Joseph could not expel them (it might lead to Jacob's death) and could not detain them (they were a threat). So he detained the most dangerous one and sent the rest home with food.
Turn the question around: Why were the brothers allowed to steal Yosef, and even sell him as a slave? That's a full-fledged violation of the prohibition לא תגנוב in the Ten Commandments - which carries a death penalty. It is described exactly that way in the piyut we say about the Asarah Harugei Malchus, in the argument presented by the evil ruler.
The answer (of course) is that they were not allowed to do it. The entire rest of the story is how that gets fixed. Yosef was the victim, he was completely allowed to punish them, measure for measure. As his brother says to him, G-d has found out the sin of your servants - we will all be slaves to [you] our master.
Yosef is not doing more to them than they deserve, he is doing less. The brothers know that and acknowledge it as part of G-d's judgment, even if they don't (yet) understand why ("They trembled, one to another, saying, 'What is G-d doing with us?!'"). During the story, Yosef's love for them overcomes his strict judgment ("Yosef could not longer hold himself back"), and so does G-d's. His love for them overcomes his pain at what they did to him, bit by bit as the story progresses, and as he sees them growing in regret for what they had done ("they did not know that he could understand them... he turned away from them and cried...") Yosef arranges the story so that they rerun the same events and the same tests with Binyamin, this time successfully, and helps them to rebuild their relationship with him.
Maybe the best story in Tanach.
Yosef was a semi king in general at the time and was looking for fulfillment of his dream that he would be the king over brothers.
A king always has the right to act extra judiciously in times of need and even kill people if warranted.
The Rambam in Hilchos Melachim 3:10 says
כָּל הַהוֹרֵג נְפָשׁוֹת שֶׁלֹּא בִּרְאָיָה בְּרוּרָה. אוֹ בְּלֹא הַתְרָאָה. אֲפִלּוּ בְּעֵד אֶחָד. אוֹ שׂוֹנֵא שֶׁהָרַג בִּשְׁגָגָה. יֵשׁ לַמֶּלֶךְ רְשׁוּת לְהָרְגוֹ וּלְתַקֵּן הָעוֹלָם כְּפִי מַה שֶּׁהַשָּׁעָה צְרִיכָה.
A murderer against whom the evidence is not totally conclusive, or who was not warned before he killed his victim, or even if there is only one witness, or an enemy who killed by accident - the king has permission to execute them and to improve society according to the needs of the time
The Meforshim on the Rambam brings various sources for this but one thing is clear. In times of need (after careful thought) kings have the right to act extra judiciously for the betterment of the world.
That would have been the case by Yosef and his brothers and Shimon's imprisonment