The starting pitcher completes 6 innings and is losing 3 to 1 when his team comes to bat in the top of the seventh. The team scores 5 runs to take the lead and a new pitcher pitches the bottom of the seventh and never loses the lead. Who is the winning pitcher, the starter or relief pitcher? The starter was going to be replaced regardless of his team taking the lead in the top of the seventh of a seven inning game.
9.17 (a) in the baseball rulebook covers wins for pitchers, and it explicitly mentions that the pitcher can be awarded a win even if removed before the team gains the lead.
9.17 Winning and Losing Pitcher
(a) The official scorer shall credit as the winning pitcher that pitcher whose team assumes a lead while such pitcher is in the game, or during the inning on offense in which such pitcher is removed from the game, and does not relinquish such lead, unless [some exceptions that do not apply here]
So given your conditions of the team retaining the lead for the remainder of the game, the starting pitcher is credited with the win.
In this case the starting pitcher would be the winning pitcher because he would get credits for all of the runs scored while he was still in the game.