Site admin can easily restrict non-enrolled users from posting replies and topics in a forum by just checking the settings ” Forum View“.
By default, anyone who attempts to access a course forum who doesn’t meet the linked Courses criteria will be presented with an access denied message.
However, you may have some situations where you want to allow non-enrolled learners the ability to still read through the forum content, but without the ability to post.
In this case site, the admin can check this box to allow non-enrolled users to access the forums.