sign(x) returns a matrix the same size as x. If the dimensions of x (and therefore sign(x)) are N-1 x 1 and the dimensions of D2 are N-1 x N-1, then these dimensions are incompatible for matrix multiplication of sign(x)*D2 (unless N = 2).
D2*sign(x), on the other hand, is valid matrix multiplication and will result in a vector with size N-1 x 1. It looks like you are then adding (diag(x)^2), which has size N-1 x N-1, so I'm not sure D2*sign(x) is what you are looking for.
Can you provide more info on what you are trying to do?