Why can’t I include echo inside a variable? [closed]

Not a WordPress question, but to do what you want you’d need to use an anonymous function.

For your example, it’s totally not needed or recommended, though.

Echo shortcut syntax (e.g. <?= $text ?>) might interest you.