The starting point is that if you look closely at the provided example, it does not use the
Geometry by expression tool but the
Geometry Generator in the Style properties of the Matrix layer.
These are slightly different as the latter will natively compute one geometry for each line of the input (Matrix) layer.
Generate the Matrix between points in layers A & B:
This Matrix layer should be a point type layer (that's what the Matrix tool generates), and since it's a layer with Geometry, you can edit it's Symbology to use Geometry Generator.
You should use this formula in the Matrix table Style
Style > Marker > Geometry Generator (type line) + the formula:
make_line(geometry(get_feature('random_a_layer_name', 'id', "InputID")), geometry(get_feature('random_b_layer_name', 'id', "TargetID")))
The difference with the provided example is that you have two different layer names for the InputId and the TargetId.
What this does, from the reference post you provided:
In the Matrix table, there is one line per pair of InputId and Target Id (if you have A and B points, it has AxB lines)
What the code does: for each pair, given by the Matrix, it creates a line, between the InputId point of table A and TargetId point of table B.
Note: for the code to work in the 'generate geometry by epression', which would be another approach, you would need to introduce lists that will iterate over all the pairs beween layer A & B. As the Matrix already contains this crossmatch, it's simpler to use it rather than a barebone expression.