You need to perform a clean install of macOS on this Mac. You want to make sure the file system is clean and macOS is complete without any nefarious software on it from the previous owner.
You may be able to boot into Internet Recovery Mode (Command + Option + R) to access the latest online macOS installer compatible with your Mac. Or you can create a bootable macOS USB installer as suggested by @P. Phillips which requires access to another Mac or reset the password on the current OS so you can create the installer.
When performing the clean install make sure to erase the whole physical drive as GUID partition and MacOS Extended (Journaled) if you are installing macOS 10.13 or earlier. Otherwise erase the physical drive as GUID partition and APFS (top option) if you are installing macOS 10.14+. Recent versions of Disk Utility hides the physical drive from view so you must first click on "View" within Disk Utility and select "Show All Devices" so that the physical drive appears on the left pane of Disk Utility. This Apple article explains how to reveal the physical drive:
https://support.apple.com/guide/disk-utility/erase-and-reformat-a-storage-device-dskutl14079/mac