I believe the Lord's purpose in all the ceremonial laws was to create and maintain a distinction between His people and all other peoples (Lev. 20:24-26). His purpose in both Testaments has always been to separate a people for Himself out of fallen humanity.

To "defile oneself" (my NASB reads "makes yourselves detestable") by not maintaining that distinction between God's people and all others is a slap in His face. It is like saying, "I don't want to be Yours. I want to be like those other people in other nations who worship other gods."

Quote
I am the LORD your God, who has separated you from the peoples (Lev 20:24). Thus you are holy to Me, for I the LORD am holy, and I have set you apart from the peoples to be Mine (verse 26).

Defilement meant the same thing to Daniel as it did to the ancient Israelites. It was immensely important that God's people maintain the distinction between God's people and others. To live and eat and dress and act as one of them would have been like counting oneself among them.