As far as I know, there is no way to transit airside between terminals at Riyadh airport, except between terminals 3 and 4.
So you need to go through immigration to exit terminal 2 before you can move to terminal 3.
This in turn means you need a visa to be able to enter Saudi Arabia, unless you qualify for one of the exemptions.
There are anecdotal reports of people who were able to get escorted from one terminal to the other airside, but I wouldn’t count on it.
Note that I wouldn’t be surprised if you actually had two separate tickets rather than a single ticket covering both flights. In that case, you will also need to retrieve your checked luggage in Terminal 2, carry it to Terminal 3, and check-in again there. In that case there is absolutely no doubt that you need to go through immigration. You would also incur all the risks associated with a self-transfer, though given the long layover time the risk is limited (but not non-existent).