Is it legal for a non-IFR rated pilot to fly a SID on a VFR flight?
It depends what you mean by 'flying a SID'. If it is just following the procedure without violation of VFR (i. e. you are above VFR weather minimums for a given airspace, you maintain your own separation from traffic, don't violate ATC clearances, don't enter controlled airspace without a clearance etc.) - yes, it's perfectly legal. You can fly any route you want, your choice (again, I assume that you do not violate ATC clearances).

If you mean by 'flying a SID' obtaining an ATC clearance to fly a SID - if it is an IFR clearance, than no, it is illegal. You cannot request IFR clearance if you or your aircraft is not IFR rated, except the cases when you are training for an IFR (and have a CFII next to you).