Yes, it is legal. There is no restriction as per visa, voluntary work is always allowed and appreciated with no restrictions. Being said all this, confirm with your board. Since, I have heard that some boards require Social Security to work as an Intern. As for me, I did my voluntary work in internship and took my Naplex in October and planning to take MPje in NC next year.
Hope this helps....