First you will need to download an app called odin on your PC or laptop, this is the tool you use to flash (or install) firmware.
Next you need to install an app called frija on your PC to actually download the firmware (alternatively you can download the firmware on your phone from sammobile.com and them transfer it to your pc, however the website is slow as it throttles your download speed so it may take hours).
Find and download the latest firmware for your region/device carrier, find it using your CSC code) for example I'm in Australia so the csc code is XSA, or if I want the firmware for my specific carrier (optus) I would choose OPS as my csc code.
Once the firmware is downloaded you need to relock your bootloader, to do this go into settings and find developer options (if this option isn't already enabled then do the following).
Go to settings - about phone - software information - then tap on build number until it says developer options enabled.
In developer options turn OFF oem unlocking. This will relock the bootloader.
Now turn off your phone(not restart) and boot to download mode. To do this plug your phone into the computer and hold the volume down and bixby buttons until the download screen appears.
Then open the odin app on your PC and place the four firmware files in the corresponding slots, AP, BL, CP, and CSC (don't use home csc). Warning this will wipe all your data and your phone will be as if new.
Once the install has finished start your phone and it should be fixed.
Please make backups of your phone data before starting this process as everything will be wiped. If anything goes wrong don't stress, you can always recover your phone and make it work again but not the data.
P.S. having a rooted device does not decrease its security, it just means that you the user have options. You can set the security however you like (higher or lower than a normal phone). The only risk is if you don't know what you are doing and do something you shouldn't or disable something that you don't know what it does then you can compromise the phones security! But If your not interested in Rooting and doing the research then it's probably best to stick to stock. Good luck