Macros only do 2 things:
1) replace instances of $param$ with the values passed into the macro
2) replace instances of $(param)$ with the values of variables defined outside the macro
Other than those two actions, the macro contents are simply "returned" for further processing in the calling context. It is this context which determines what happens next. If the macro occurs within wikitext (your first example), then the macro call is replaced by its output and parsing continues with the first character of the replaced content. If that output contains a macro call (as in your example), then that macro is processed, and its contents are returned for further processing. Thus, multiple layers of macro calls are *iteratively* expanded. If a macro call invokes itself, then this is would be referred to as *recursive* expansion.
In contrast... if the macro call is used as a parameter value in a widget, then the macro call is replaced by its output as before. However... all further processing is left to be handled by the widget itself. This also applies when the macro output is used as a parameter value in HTML syntax, giving the results that you see in your second example.
If you want a widget or HTML parameter macro call to be iteratively expanded, then you can do this explicitly, by using the <$wikify> widget. Thus:
<$wikify name="myparam" text=<<bar>>>
<span class=<<myparam>>></span>
</$wikify>
-e