To determine if a salt is soluble you need to work out the change in Gibbs energy, which combines enthalpy (internal energy) and entropy (disorder) into a single value. Only if the solubility process causes an overall reduction in Gibbs energy, then the salt is soluble (Here it's explained for NaCl https://www.linkedin.com/pulse/solid-liquid-solubility-how-does-work-nikhilesh-mukherjee/).
∆G = ∆H - T∆S [ G is Gibbs free energy, H enthalpy, T is temperature and S is entropy]
Lattice energy: energy required to convert the crystal into infinitely separated gaseous ions in vacuum.
Hydration energy: the amount of energy released when one mole of ions undergoes hydration
Lattice energy BaSO4= +2474 kj/mol
Hydration energy BaSO4 = -2368 kj / mol
T = 298 k, ∆S = 102 j/k-mol
∆H = Lattice energy + Hydration energy = 2474 + [- 2368] = +106 kj/ mol
∆G = [106 – 298 x 0.102] = +75.6 kj / mol (positive therefore BaSO4 is insoluble!)
Now, let's see MgSO4:
Lattice energy MgSO4= +2833 kj/mol
Hydration energy MgSO4 = -2927 kj / mol
∆H = Lattice energy + Hydration energy = 2833 + [-2927] = -94 kj/ mol
The enthalphy change associated with the solubility of MgSO4 is negative (-94 kj/ mol), given the entropy contribution is always negative when salts dissolve, then you can immediately conclude that the change in Gibbs energy is negative, this means MgSO4 is soluble!
https://chemistryklipz.files.wordpress.com/2016/12/born-haber-cycles-and-enthalpy-of-solution.pdf
http://chemistry-reference.com/reaction.asp?rxnnum=88