W=mxg is derived by f=mxa
where f-force
m=mass
a=acceleration
due to gravity when the object fall down due to gravity it becomes f=mxg
as we need to find the weight of the object we need put w (weight) in the place of f (force) so it become
w=mxg