Spellcasting Contract is unaffected if it was not prepared
Spellcasting Contract says:
This spell functions exactly like imbue with spell ability, except that you can imbue the target with any spell you have prepared (instead of just abjuration, divination, or conjuration [healing] spells) and the target may have more than one use of the imbued spells, depending upon the arrangements made when it is cast.
Imbue with Spell Ability likewise says:
You transfer some of your currently prepared spells, and the ability to cast them, to another creature.
Let's call these two the "imbuement" spells, while the spells that you implant/imbue into another creature, their payload so-to-speak, is the "imbued" spell.
How does imbuing work?
Now matter how you cast either of these two imbuement spells you get their effect, namely you imbue a prepared spell. It does not matter if you got to cast the imbuement spell because you prepared it or because you used a wish to cast it. All that matters is that the spell you imbue is on your list of prepared spells when you imbue it. So you can imbue any of the spells you have currently prepared1, 2.
The ability says you also transfer "the ability to cast them". For you as an arcanist, that ability consists of an unused spell slot of an appropriate level. I think this is up to a bit of GM adjudication, but if you also transfer that ability, it would make sense to transfer one of your free spell slots with the spell, which then is not available to you while the spell is imbued. Once they use the spell, the slot would become free again to regain. But I think there are no explicit rules on this combination, so ask your GM.
For example, if you imbue a creature with cure light wounds, that is the prepared spell you transfer, along with a first level slot. The spell you transfer has no limitations to being replaced in your list of prepared spells, only the imbuement spell is restricted from being replaced. Once it has been imbued, you can replace the prepared cure light wounds for another spell you prepare, with no effect on cure wounds that is currently is imbued into the target creature.
What about not being able to replace the prepared imbuement spell?
Spellcasting Contract says:
Once you cast this spell, you cannot prepare a new 5th-level spell to replace it until the contract expires.
This restriction only refers to Spellcasting Contract itself, not to the spell you imbued. If you did not prepare Spellcasting Contract, then there is no impact on you. There is nothing to be replaced, and other spells you prepared are not under any restriction to be replaced. This has nothing to do with spell slots.
Likewise, for Imbue with Spell Ability:
Once you cast imbue with spell ability, you cannot prepare a new 4th-level spell to replace it until the recipient uses the imbued spells or is slain, or until you dismiss the imbue with spell ability spell. In the meantime, you remain responsible to your deity or your principles for the use to which the spell is put. If the number of 4th-level spells you can cast decreases, and that number drops below your current number of active imbue with spell ability spells, the more recently cast imbued spells are dispelled.
Again, it only refers to Imbue with Spell Ability, not the spell you imbued. Unless the number of your 4th level spells you can cast somehow falls under the number of active imbued spells, there is again no impact. You have not prepared the spell to begin with, so there is nothing to be replaced, and other prepared spells are not exempt from being replaced in the normal manner.
It would make sense to apply the same restriction of needing a number of spells you can cast to 5th level in the case of Spellcasting contract, if you read "4th level" as "the level of this spell". Purely RAW, it says "4th level" however, so if it works "exactly like Imbue with Spell Ability", you still would be limited by your 4th level spells, not the 5th level ones.
So, enjoy your free profit (well, if you consider burning a wish to be free).
1 As an acanist, you do prepare spells
An arcanist must prepare her spells ahead of time, but unlike a wizard, her spells are not expended when they’re cast. Instead, she can cast any spell that she has prepared consuming a spell slot of the appropriate level, assuming she hasn’t yet used up her spell slots per day for that level.
2Because the imbuement still falls under the rules of Imbue Spell Ability where not explicitly overruled, you are still limited to spells of no more than second level, which you can imbue if the recipient has 5 or more HD.