Try this you can select the 5 products by subquery and join with images so you will get the records for 5 products,no matter how many images each product have
SELECT * FROM
`gallery` g
INNER JOIN
(SELECT * FROM `product` LIMIT 5) p
ON( p.product_id = g.product_id )