"Is this legal?" refers to the subject line "tax write-off on sponsorship."
There are two forms of deductions that might apply here. If the organization that received the money qualifies as a charitable organization, the amount is a charitable contribution and the amount (less any benefit derived from making the sponsorship).
If the sponsorship nets some publicity (do you get signs, ads in the program, patches on the uniform, etc...) it might qualify as an advertising expense.
Of course, not all good deeds are recognized as deduction-worthy by the IRS.
Of course, not enough information here. The company's tax professional will need to revue the situation.