With versions 5.2, 8.0.4 and 12.3.1 on Windows 10 x64 I get the same result:
Exactly this aspect of
Return behavior was earlier discussed in the following thread:
In this answer (from another thread) Chris Degnen provides a link to this 2009 year MathGroup post by Leonid Shifrin where he argues that this behavior isn't a bug:
My feeling is that this is not a bug.
There are two possible outcomes for any expression wrapped in Return: either
it is inside some lexical (or dynamic) scoping construct for which the
action of Return is defined - and then Return disappears as a part of
breaking-out-of-the-scoping-construct procedure, or it is not and then it is
just a symbolic expression like any other. It seems like neither Function
nor CompoundExpression are considered by Mathematica as the scoping
constructs for which the action of Return is defined as for example for
Module, Block, With, etc.
Under this assumption, your puzzle can be reduced to a simpler one:
The latter discrepancy can be explained by consulting the exact rules of the
evaluation procedure. Lacking a more up-to-date account, I cite here David
Withoff's "Mathematica internals" of 1992:
The very last step of the evaluation loop is (Chapter 3 - evaluation, p. 7,
on the bottom):
"Discard the head Return, if present, for expressions generated through
application of user-defined rules."
Thus, when you use SetDelayed, you create user-defined delayed rule and then
Return is discarded, while for "direct" evaluation like
it is not.
At least, things seem to work as documented in Withoff's technical report.
One thing that would be nice to have is a complete list of scoping
constructs for which Return is discarded when whatever it is wrapped around
is returned from that scoping construct.
Also, a telling comment by Daniel Lichtblau:
I know at least one developer who would require psychoanalysis,
possibly forensic in nature, were he to ever again try to carefully
consider the inner workings of
Return. – Daniel Lichtblau Sep 28,
2016 at 19:09