3d input for Dense Layer Keras
In a regular fully connected layer (Dense), the computation is done using the following Matrix operation : $$R = A*W + B$$
With all matrixes being vectors (if batch size = 1), exept $W$, which has size(inputsize, outputsize).
for a 3D input, the way TF computes the output is simply by applying this formula only to the last dimension, considering all other dimensions as similar to batch sizes.
So in your example with input of size (4,3,2), Tensorflow 'flattens' the vector into a (12, 2) matrix, computes the result as if it was a 2D input, this gives a (12, 5) vector, and then 'unflattens' the vector to give back its 3 dimensions (4,3,5).