Using the action economy, the rogue would need to hide each turn
To make this work, since both the cunning action 'hide' and the spell damage consume a bonus action, and you only get one bonus action per turn, the rogue needs to use his/her action to hide. But that also means that, as Sdjz points out, when the attack is made the location of the attacker will usually become evident. (See below for more on that).
Sequence
Round 1: Cast spell using bonus action, hit/miss, hide. (Rogue now hidden)
Round 2: attack using bonus action, hit/miss, hide. (Rogue now hidden)
Rounds 3-10: rinse and repeat.
But are you 'hidden' for purposes of getting advantage on the attack per the rules on unseen attackers, PHB p. 94? The attack itself reveals the PC who then needs to hide again.
But what if I am behind total cover?
The question that this situation has raised to me is: does the "that you can see" criteria apply to this spell? It's not in the spell text.
Basic Rules, page 102.
When you cast the spell, you can make a melee spell attack against a creature within 5 feet of the weapon. On a hit, the target takes force damage equal to 1d8 + your spellcasting ability modifier. As a bonus action on your turn, you can move the weapon up to 20 feet and repeat the attack against a creature within 5 feet of it.
The rogue might be able to remain hidden by using total cover, and never be seen. Given the lack of "that you can see" in the spell text, the rogue could conceivably make the attack from total cover since that text's absence (so common in other spells) implies that the rogue need not see the target.
- That makes no sense to me (as either player or DM) since how does the PC know where the target is to attack, or if the target is in range (60' away or less)? Use of some spells or magic items might allow for this -- spells such as wizard eye when your warlock class goes up higher -- since spiritual weapon does not use concentration.