The moment a teenager launched a bottle attack on a man who was branded a paedophile and beaten to death with rocks has been shown in court.