$posts = Post::where('post_name', 'LIKE', "%{$post_name}%")->whereHas('categories', function($query) use ($category_id) {
$query->where('id', $category_id);
})->paginate(50);
Documenation: https://laravel.com/docs/7.x/eloquent-relationships#querying-relationship-existence
But I think that your logic is wrong.
Post belongs to Category, so post should have a category_id
Another things are Tags, Post could have many Tags, and Tags could have many posts.
In that case it's many to many relationships.
But that code above will work.