How add dimensions[0] of selected objects?
You overwrite dim and dimX in every iteration of your loop, you do not add something to a list.

If you need a list of all dimensions you can use

dim = []
for i in bpy.context.selected_objects :
    dim.append(i.dimensions[0])
dimX = sum(dim[:])


dim will then contain all dimensions and dimX will contain the sum. dim is initialized as an empty list and the loop appends the dimensions to it. Note the indentation of the last line: dimX needs to be on the same height as for, otherwise python will think that it belongs to the for loop and execute it in every iteration.

If you just want the sum of the x dimensions you can add them up into a variable that you initialized with 0 first:

dimX = 0
for i in bpy.context.selected_objects :
    dimX += i.dimensions[0]