I want to disconnect metamask wallet using web3 or ether.js But I cannot find any function to disconnect programly.
It can not be done programmatically, because it is up to the user to disconnect/connect, you have no control(from code level) over metamask wallet. You just simulate flow of logging in and logging out by checking if you can get access to user's wallet accounts.