Sometimes there are possibilities of user clicking on unknown links or land on malicious sites or  download some apps, that may lead to unwanted apps installing without permission on a device. To prevent it, users can enable the security settings in the device to ensure that the unwanted apps are stopped from getting installed. Users need to go to Settings>Security>Unknown sources and uncheck allow installation of apps from (unknown sources) for this.

Also users should keep the device's operating system and apps up to date, regularly monitor them, delete unwanted apps and use security software that can detect and block malicious apps