A common argument for restricting immigration to the United States and other developed countries — maybe even the most plausible one — runs like this. Opening the borders will bring in people who will consume more public services than they pay for in taxes and who will vote for more statist politicians who support those public services. The result will be less freedom for everyone in the long run. Therefore, many conservatives say, immigration control is a regrettable but necessary step to securing freedom.
Meanwhile, a common argument for restricting gun ownership in the United States and other developed countries — maybe even the most plausible one — runs like this. Opening the market to the free sale and possession of guns will allow criminals to get their hands on deadly weapons, perhaps through theft if not legal purchase, resulting in more murder and less freedom in the long run. Therefore, many progressives say, gun control is a regrettable but necessary step to securing freedom.
These common arguments for restricting immigration and restricting gun ownership are surprisingly similar in form. They show us that the reason why fierce immigration control advocates are generally not also fierce gun control advocates (and vice versa) has more to do with ideological confirmation bias than sound logic.
Furthermore, both these arguments make a questionable implicit assumption: that it is morally acceptable to take away the freedoms of some people to secure the more important freedoms of others.

When is it morally acceptable to restrict freedom?

It might be morally acceptable for you to steal my car to prevent a murder across town.”]
In some emergency scenarios, we might be tempted to agree with this assumption. For instance, it might be morally acceptable for you to steal my car to prevent a murder across town. I’m not sure this is true, but let’s concede for now that it might be true. Even if it is true, we generally think that you still need to return my car once you no longer need it to prevent the murder, and that you need to compensate me for any damages and trouble you caused.
Few of us would think it acceptable to set up a standing policy of car theft for murder prevention. Should we have a permanent division of the police to go around stealing cars when they think they’re necessary for otherwise legitimate police work? Surely not.
Furthermore, virtually everyone would agree that  stealing the car would have to be the least invasive way of preventing the murder. If there’s a way to prevent the murder that doesn’t involve stealing at all, like using your own car or paying a willing driver, you must not steal.

Can violating one freedom promote another, greater freedom?

The advocates of immigration- and gun-control policies seem to think we should have a standing law-enforcement body to go around violating freedoms in the hope that a greater gain in freedom will happen down the road. How is this different in principle from setting up a division of the police for commandeering cars — or a division of the military for commandeering homes, a practice of the 18th century British army banned by the Third Amendment to the US Constitution?

It isn’t okay to take away freedoms systematically on the basis of mere speculation — only on hard, indisputable evidence.”]
Even if violating some people’s rights to protect more people’s rights through standing enforcement agencies is morally acceptable in principle, advocates of such measures need to show that the violation of freedoms will actually work in the way that they claim. The burden of proof is on them; it isn’t okay to take away freedoms systematically on the basis of mere speculation — only on hard, indisputable evidence.
In the case of immigration and guns, that evidence is thin and disputable. Legal immigrants are, on the best evidence, a small net fiscal burden to existing US taxpayers, on average.[1] Is stopping a small net fiscal burden a greater gain to freedom than the loss of freedom associated with immigration law enforcement? That seems unlikely.

Are there alternative solutions that don’t violate freedom?

Moreover, an alternative, less invasive solution to the fiscal burden problem would be to make immigrants ineligible for more programs. In the same way, a less invasive solution to the problem of immigrant votes for statists would be to make earning the right to vote more difficult than obtaining the right to live and work in the United States. It is also questionable whether immigrants tend to vote for statists; certainly, anti-immigrant rhetoric from the right makes immigrants less likely to vote for right-wing parties.
On guns, there is a big debate in the literature, but there are just as many high-quality studies finding that gun regulations increase violent crime as there are studies that find that they reduce violent crime. Many find no effect at all, and one points out that different modeling assumptions have a substantial effect on study results, such that basing a policy decision on any particular model is dangerous. Even if gun laws did reduce crime a little, we don’t know whether other, less intrusive methods of reducing crime, such as supporting mental health treatment, would work just as well.
The principal arguments for restricting immigration and for restricting guns both depend at minimum on the assumption that it is acceptable to take away some people’s freedoms on an ongoing basis whenever doing so preserves greater or more important freedoms. This assumption implies some absurd conclusions, such as it being okay for police to steal cars for their work rather than buy them.

Less invasive means for solving the supposed ills of immigration and gun ownership do exist.”]
A weaker, more plausible premise, that it is acceptable to take away freedoms if doing so is the least invasive available means for preserving greater freedoms, still cannot justify immigration and gun laws, because less invasive means for solving the supposed ills of immigration and gun ownership do exist. Moreover, the evidence is thin as to whether immigration- and gun-control laws even promote greater freedom at all — more likely, they simply reduce freedom.
[1] A careful analysis of native- and immigrant-headed households in New Jersey found that, looking at just state and local public sectors, “native households in New Jersey bear a total net fiscal burden of $232 per native household from the fact that the average immigrant-headed household receives $1,484 per immigrant household more in state and local services than it contributes in state and local taxes.” In California, “the average native household contributes a fiscal surplus of $283 per household to fund a fiscal deficit of $831 per immigrant-headed household.” However, immigrants are a net contributor at the federal level: $127 per immigrant household in California and $520 per immigrant household in New Jersey. That still works out to a small net fiscal burden from immigrant households.