Before they even started dating Shiny and Cadence had been divorced for awhile. And although AJ would feel awkward around Cadence at first, that would gradually fade. I’m not a writer so I won’t make dialogue for this, but Cadence is supposed to be telling AJ she’s okay with everything in this picture. They eventually become pretty good friends.
The princess of love can feel love, when it’s fading or growing. I headcanon she can basically see relationships like strings connecting beings. Anyways, she knew when her and Shiny were growing apart and basically sent him to live with Twilight for awhile. Shiny did odd jobs around ponyville, finding he really enjoyed the work around the farm. He and AJ hit it off and she became someone he could confide in about his problems. Eventually when he returned to Cadence they spent awhile talking it over before deciding to go through with a divorce. You can guess the rest~
And yes AJ is preggers here.