Prevent all users from editing posts except admins using hooks

You can take away users’ capabilities with a plugin like User Role Editor, or programmatically. What you’ll need to do is collect a list of all your post types that appear in the Editor (Core has Post and Page; plugins and themes may add more) and then remove properties with a plugin.

For example, you can prevent Editors from being able to edit Posts with the following code:

<?php
/**
 * Plugin Name: Lock down Posts
 */

add_action( 'admin_init', 'wpse_407959_restrict_caps' );

function wpse_407959_restrict_caps() {
    $role = get_role('editor');
    $role->remove_cap( 'create_posts' );
    $role->remove_cap( 'edit_posts' );
    $role->remove_cap( 'edit_published_posts' );
    $role->remove_cap( 'delete_posts' );
    $role->remove_cap( 'delete_published_posts' );
    $role->remove_cap( 'publish_posts' );
}

Check your own site to determine all the Roles you need to update, and also check each post type’s capabilities list. Some custom post types use default capabilities (i.e. removing edit_posts may prevent them from editing your CPT as well) but others map their own custom capabilities you’ll also need to remove.