Is it beneficial to publish papers not related to your primary research field?
I'm honestly surprised at the question.  "Primary" does not mean "only"!

If it's a good paper, then of course you should publish it.  Aside from the obvious personal benefits of making you look more diverse, increasing your visibility in another field, and possibly creating opportunities for future collaboration, you're doing what research is for: expanding human knowledge.  And if it's not a good paper, then of course you shouldn't publish it, even if it is in your primary field.

But to echo shan23's comment: Don't use grants in area X to fund research in area Y.