Legal Puzzle for my Legal Readers

Here's the hypothetical:

Plaintiff files a civil lawsuit seeking only declaratory relief. Plaintiff wants a declaration that defendant's actions violated "Statute X."

Then plaintiff files a Motion for Summary Judgment, seeking only a judicial declaration that defendant's actions violated "Statute X."

Defendant opposes the motion, asking only that the court deny plaintiff's motion. Defendant does not move for or request any relief other than the denial of plaintiff's motion.

The court hears the motion and finds that defendant's actions did not violate "Statute X." as a matter of law. The court denies plaintiff's motion.

Here's the question: As the court has now determined the only legal issue in the case, and nothing remains to be decided, could the court enter judgment for the defendant? Even though the defendant never formally requested it? Or would that require another motion, presumably to be brought by the defendant?

Put another way: Could a court enter a judgment against a party who moved for judgment in its favor but lost, when the opposing party never sought a judgment in its favor in the first place?

Any thoughts would be appreciated (use the comments or email privately to john-at-legalreader-dot-com). Bonus points to anyone who cites California state law authority on point.

Cheers!