Legally there is nothing to say that the principal employer is liable.
Unfortunately, the courts have decided otherwise. There are many cases, including some at Supreme Court Level.
This particular case decided by Madras High Court very clearly states that Principal Employer is liable for gratuity to be paid to the contract workers in addition to the liability of the contractor. the judgement is detailed and will take a time to read. but the judgement clearly states that Gratuity is covered in sec 21(4) of Contract Labour Act.
https://indiankanoon.org/doc/1632593/
I would of course, be happy if the seniors on the group give their opinion, because this matter has come many times in our audits and there is a regard dispute on this.
There was also a decision by SC in the case of SPIC or one of its fertiliser subsidiaries for contract labour used in Chennai Port, which I can not find at the moment