Indeed. But all laws passed by Congress with respect to the territories were not necessarily constitutional. Case in point, the Missouri Compromise, which partitioned the territories into slave and non-slave portions, was ruled unconstitutional by the Supreme Court.
The following wasn't involved in that decision, but going back to the language of the treaty by which we obtained the Louisiana Purchase (the properties partitioned by the Missouri Compromise), one finds that the residents of the Louisiana Territory had the right to hold their property (which under the laws of the times included slaves) anywhere in the Territory. Or words to that effect. Of course, treaties are considered the law of the land because they are approved by the Senate, a vestige of state sovereignty where every state has an equal vote in deciding the course of the nation.