One well-known unofficial service pack for W98 steals many elements from WMe, so I would consider it completely illegal if one doesn't have a WMe licence.
Then, Microsoft alleges that decomposing and recomposing software isn't allowed by their so-called licence agreement. However, the licence agreement isn't the law, and several courts in the EU have decided against the so-called agreement.
So modifying W98 with pieces written by yourself (like painting new icons, programming a stable VMM...) is very probably legal and little risky. Complete forums exist for that.