I have an ERC20 token XYZ smart contract created. People will send certain amount of tokens back to the contract address to initiate certain functions. I just want to know that what will happen if someone send other tokens to my contract? May be token ABC, UUY, etc, like any token other than my own "XYZ" token. I want to grab those tokens in my other wallet and dont want to initiate any functions based on those. I think any functionality that can check address of the tokens sent can be beneficial, but I am open to suggestions.
You can't prevent tokens being sent to a contract as the tokens are not explicitly sent anywhere, only balances are shuffled around. Furthermore due to the same reason you can't detect when your token receives tokens. You can read more about this for example here: Smart contract that receives only one token
You can, however, add functionality in your contract to handle the other tokens - for example transfer them to another wallet. But this kind of check has to be initiated by someone (probably you) and you have to tell the contract which tokens to check - the contract can't check all possible token balances.
Easiest would be probably to include basic token transfer functionality in your contract (not to only transfer the token created by the contract but other tokens) and to implement a backend system which checks for token balances and initiates a token transfer if needed. But also in this case your backend system has to know which token balances to monitor.