Nothing about being polymorphed prevents you from being able to do melee spell attacks
As you say, casting the spell and keeping it up is not an issue in polymorphed form regardless of what you turn into. In fact, there are no mechanics that say this will not work.
A melee spell attack is something granted by an effect of a spell. If the spell says that you get a melee spell attack and the creature you polymorph into meets all the qualifications for that spell, then you can make a melee spell attack in that form.
In your example case specifically, the ape would still be in control of the spell and there is no rules that say anything against an animal being able to do melee spell attacks from spiritual weapon. There are no limitations put on the spell beyond what is written in it and an ape does not run afoul of any of them. So, nothing in the rules prevents an ape from making melee spell attacks with spiritual weapon.
The only area that might even come close to preventing you from using this effectively as an ape would be the DM adding additional conditions outside the rules preventing you from being able to do this. For example they might take issue with the ape's intelligence which you assume when you polymorph into it. It isn't clear from the spell what is involved narratively with regards to the bonus action to move and attack with the spiritual weapon, but a DM might say that the ape is not intelligent enough to understand how the spell works enough to use it effectively.
This would be outside the rules since the spell makes no such rules or limitations however.