Welcome and no worries.
Assuming
one reservation also means
one fare, most likely the AC codeshare did not have any seats in P class on the LH FRA-IST flight at the time of booking, LH actually might have had seats available under their own flight number though because the aircraft definitely has a two-class configuration.
But to your questions, if your P fare allows for same-day changes, you should be able to do this but if you are trying to get into LH Business Class this way, I bet that LH requires that P class needs to be available which is highly unlikely so close to the departure time.
Mileage-wise, each segment will be treated individually and the indiviual booking class counts rather than the overall fare you purchased.
So the AC YUL-FRA segment in P will earn you 200% PQM with UA MP and the LH FRA-IST segment in Y (assuming AC Y = LH Y) will earn you 150% PQM with UA MP.
PQM-wise you are actually better off sitting in Y in this case as P class on the LH segment would have earned you only 100%, see
united.com
However, if you care about the meal and the open middle seat on the FRA-IST flight, rather than requesting a formal same-day change, I would just ask nicely in the LH lounge or at the gate in FRA if they are able to get you a seat in Business Class since you purchased a Business Class fare, it worked for me multiple times - and even when they give it to you the flight should still post as Y class (150% PQM) to your UA MP account.