Your wallet automatically handles that, when you generate the wallet, keys and addresses are generated, the master private key generates the child keys. The child private key generate a signature while spending, to prove you are the owner of a public key while not revealing the private key. Without the signature, you can not be able to spend. So, without private key, you can not spend your coins. To understand better, if you import the master public keys (not private key), only child public keys and addresses are generated which are used for watch-only wallet, in watch-only wallet, you can not spend because it has no private key, it is used for just making an unsigned transactions and for tracking transactions.
Learn more from here:
https://learnmeabitcoin.com/beginners/digital_signatures#:~:text=A%20digital%20signature%20is%20something,digital%20signature%20to%20prove%20it.