I went to Canada once to pay the import duties on a gift and mail it to my friend on the other coast. When I told the Canadian border guards that that is why I was visiting Canada, they told me to pull over and go inside. I went in, they took my iphone, asked for the pass code, charged me the duty on the item I was importing, and then had me sit there for two hours while they went over my car. After letting me go on my way, I drove to Surry, taped the box closed and dropped it at the UPS Store there. Then returned to the US. When the US guards saw my entry time they asked why I visited Canada for only 30 minutes. I told them the exact same thing I told the Canadian guards, they laughed and waved me through.
BTW, Canada won't let you in if you have a criminal record or even a DUI citation.
When I flew to Rome a couple years ago there are two lines for immigration. One is for Europeans and the other is for everyone else. A guard saw me standing in the everyone else line while holding a blue American RFID enabled passport and pulled me from the line and sent me through the Europeans line. It took me two minutes to get through immigration. My friend arriving from SEA spent an hour and a half and was interrogated about where we were staying, what we were doing, verified a return ticket, and so on.
The moral of the story is that every country weighs risks, costs, and benefits every time they let someone in.
Borders are a thing and controlling who crosses borders is one of the fundamental and defining characteristics of a country.