The main part that rattles is the boot latch. You cant really stop it rattling unless you remove it, and then you'd have to find a way of securing the tailgate.
Try removing everything from inside the boot lid (wiper motor, washer tubing, solenoids etc) and filling the boot lid with expanding foam, it won't stop the latch rattling but the tailgate wont have any flex in it. Don't put too much in there though as it will push out the boot lid when it expands!