It's legal to kill an intruder as long as it can be justified.
You cannot just kill an intruder because they are in your house unless you are in danger and cannot safely retreat from the house.
However you could hold the intruder at gunpoint and if they refuse to leave the house and try to harm you or your family then you could kill the intruder.
But do be prepared to be arrested when the police show up because some police will decide to arrest you and then let the court decide whether or not the shooting was justified.
If possible it's best to just leave the house and get your family out of the house until the cops get there to take care of the intruder.
But sometimes there's no other choice to shoot the intruder.
Sadly though some people do get charged with murder and go to prison even though the shooting was justified.
So be cautious and only shoot the intruder if their is no other option.