Is it correct to use 'He had been married before'?
Solution 1:
It is not incorrect. However, she hadn't realized X is generally used to point out that up until some time or event, she had not (yet) realized X. For example, Until Julia met Scott's fourth ex-wife she hadn't realized that he had been married before.
Otherwise, if you just want to say that at the moment when she met him she did not know he had been married previously, then say that: When Julia met Scott she didn't realize he had been married before.