The gemara raises a question if one would shecht two animals for a korban on shabbos when only one is needed and then find a weakness in the korban that makes it inferior (albeit still kasher) which retroactively entitles the shechting of the second one (since the gemara concluded that due to הקריבהו נא לפחתך one is allowed to shecht a better animal even if the first was acceptable), is this a violation. Conceptually, it is a situation where one intended to violate a prohibition (yet it is accidental as rashi explains because they thought it was permitted and were mistaken), and in the end did not violate the prohibition - do we focus on the intent rendering this a violation or on the action which was ultimately permitted. The gemara says that this is dependent on the machlokes Rabba and Rava where one would throw in a net intending to catch fish, and draw up in the net a drowning child together with the fish. The concept is the same, the action was permitted but the intent was to do something forbidden.
In analyzing the case of the net to catch fish, the gemara indicates that the machlokes is because ultimately fish were caught and a child was also saved. Had the child not been saved, all would obviously agree that he is chayev for trapping fish. The implication is also that had he only saved the child and not succeeded in capturing the fish, all would agree that he is exempt. Meaning, the only reason for Rava to say he is chayev is because ultimately he did an issur of catching the fish. This raises a fundamental question - How is this comparable to the case of the korban where at the end it was realized that the second animal that was shechted was permitted to be slaughtered since the first wasn't ideal? How can the gemara compare the case of the animal where he ultimately didn't do an issur on the shechting of the second, to the case of the trap where he did an issur of catching fish?
The Shita MiKubetzes raises the same question but from another perspective. If one intends to eat non-kosher and "accidentally" eats kosher, he is obviously not chayev since he didn't violate any prohibition. How can Rava consider the person chayev for shechting the second animal? The Shita answers that when one ultimately ate kosher there was no violation of anything, but here he should not have shechted the second since the first was kasher and he couldn't be sure that the second would be any better than the first. With this the Shita explains the connection to drawing the child together with fish in the trap - we consider it to be an issur since his intent was to catch fish and he actually caught fish which is assur, even though the same action for the purpose of saving the child is permissible.
The comparison only makes sense if we assume that the first animal shechted was acceptable but not ideal (had the information been known, it would be permitted to shecht the second). However, when the Rambam codifies this halacha (Shgagos 2:15) he writes that the first animal shechted was found to be a treifa, rendering it completely invalid. According to the Rambam, the act of shechting the second was completely permissible and no prohibition was violated at all. This should be comparable to one he ate kosher thinking it was treif, or spreading a trap intended for fish and rescuing a drowning child (and no fish). According to the Rambam's approach the gemara seems inconsistent in the comparison and we have no understanding of Rava's opinion who holds that you are chayev (Rambam paskens patur like Rabba)?
The Chazon Ish (kodshim, menachos 42:18) explains that the question of the shita mikubetzes about eating kosher when intending to eat non-kosher is not related to this discussion at all. When one does a permitted act, it is irrelevant that his intent was for a forbidden act. But, in the gemara's cases he is not doing a permitted act, he is doing a forbidden act of trapping or slaughtering on shabbos, in a situation where he is entitled to "push off" shabbos (perhaps this is based on the Rambam's opinion that shabbos is דחויה for pikuach nefesh and not הותרה). The Rashash similarly asks from many sources where we see that one is not held responsible for a thought to do an aveira and takes the same approach as the chazon ish - the only point of dispute is when one does an act that is technically an aveira but permitted for a mitzvah purpose. The machlokes between Rabba and Rava is whether the right to do a forbidden act to save a life or for avoda in the mikdash is only when the intent is for that mitzvah. Rava holds that if one isn't intending for the act of mitzvah i.e. saving a life or shechting for the purpose of having a better animal, there is no right to push off shabbos, and he is chayev. Rabba holds that the focus is on the action, not his intent and since the action he did is completely justified, he is not liable. Based on this approach, the fact that the Rambam describes a case where the first animal was a treifa, doesn't change the comparison because the bottom line is that if we follow action it is permitted, yet without intent for the permitted action we consider the slaughtering or the trapping to be a violation of shabbos.