List random posts on single page in the current category

This happens because you use a foreach loop on post categories. You can display random posts from the first returned category by getting rid of the foreach loop and using $categories[0]->term_id as your category in query args.

You can also try to grab all the category IDs for all your categories and include them as comma separated list. This will return 8 random posts from all categories associated with your post. Read more in the ‘Paramaters’ section of get_posts function.