From reading your code, I suggest that you implement
${\tt adjointMatrixCommutator}$ as a function to avoid code duplication.
adjointMatrixCommutator[x_, basis_] := Module[{vars, f},
vars = Array[f, Length[basis]];
Flatten[ vars /. Solve[ Flatten[Plus @@ (vars*basis)] == Flatten[Dot[x, #] - Dot[#, x]], vars]]] &;
In the definition, I have used the built-in functions
${\tt Flatten}$,
${\tt Solve}$ and
${\tt Dot}$. Please use the help menu to learn how these functions work. Next, I will define a function
${\tt adjoint}$ that will generate the matrices that you want.
adjoint[basis_][x_] := Transpose[Map[adjointMatrixCommutator[x, basis], basis]//MatrixForm;
In the above code, I have used three build-in functions:
${\tt Transpose}$,
${\tt Map}$ and
${\tt MatrixForm}$. As before, use the help menu do see what these functions do. If you wish to use the result of the function
${\tt adjoint}$ in subsequent calculations, remove
${\tt // MatrixForm}$ at the end of the definition.
Finally, let's test the function
${\tt adjoint}$ by using the example that you commented in your file.
a1 = {{1, 0}, {0, -1}}; a2 = {{0, 1}, {0, 0}}; a3 = {{0, 0}, {1, 0}};
basis = {a1, a2, a3}; ad = adjoint[basis];
ad[a1]
ad[a2]
ad[a3]
I hope that, my suggestions address your problem.