Вот для старой версии написал, через переменные.
SELECT
u.*,
ui.`image_name`,
(SELECT COUNT(il.`id`) FROM images_likes AS il WHERE `il`.image_id = `ui`.id) AS count_likes,
FROM users AS u
LEFT JOIN (SELECT id, user_id, image_name,
@row_num := CASE WHEN @row_num_val = user_id THEN @row_num + 1
WHEN (@row_num_val := user_id) IS NOT NULL THEN 1
END rn
FROM users_images, (SELECT @row_num := null, @row_num_val := null) AS x
ORDER BY user_id, id
--select row_number() over(partition by user_id order by id) rn, user_id , id, image_name
--from users_images
) AS ui ON ui.user_id = u.id and ui.rn <= 5
WHERE u.flag > 0
P.S. должно работать, но писал по памяти, не тестил, лень ;-)