Clearly you are giving these questions a lot of thought.
Sadly, in many cases it is, indeed, illegal to help a person.
In our history, we can refer to the Quakers (Society of Friends.) The crime of treason can be described as giving aid or comfort to the enemy. Yet Quakers choose to adhere to Christ's teachings to "love your enemy." Consequently, both in England and later in the United States, Quakers were/are persecuted and prosecuted as traitors according to law. They argue that they must obey God rather than the "law of men," (and eventually won the right to be conscientious objectors.)
This pertains to your example of giving sanctuary to an illegal immigrant in one's house. Breaking the law in this way ~ as an individual ~ would be very risky. But many religious groups do exactly that ~ as faith organizations. ~ A Presbyterian or Methodist congregation may decide to give sanctuary to a mother threatened with being deported. A Catholic parish might shelter several families to protect them from being taken to ICE camps. Church World Services, Lutheran Refugee Services and other organizations might take even broader actions that would be extremely dangerous for private citizens to undertake on their own.
By acting as a congregation, denomination, or organization, people of faith can access resources to mount legal defenses against laws that contradict the teachings of Christ and would prevent them from exercising their faith.
Immigration is not the only issue that pits the mandates of faith against local, state, or federal law. Specific cities have passed legislation that makes it illegal to set up public food kitchens or distribute food to the homeless. Faith communities have opposed and defied these laws, going to jail when necessary, and arguing in court their right to practice deeds of charity.
I'm afraid I could go on and on! You might want to look up Sojourners (on Facebook or the publication) and Jim Wallis, also on Facebook. Also the actions and writings of Rev. William Barber II. For more scholarly study, look up the works of Dietrich Bonhoeffer, perhaps beginning with "Life Together."
Specifically on immigration, the book, "No More Deaths," by Sue Lefebvre, is available on Amazon.
Blessings of grace, strength, and discovery in your studies!