If you can open the case without damage, then yes.
The memory in the 21.5 iMac cannot be changed without tinkering. The 8 GB that are inside should be enough for the part anyway, if a Fusion drive is inside.
Otherwise, replace the HD with an SSD and it will be in full working order again.