Yes, you can replace the logic board of the same MacBook Pro vintage.
If you are replacing a 2017 15-inch MacBook Pro logic board with another 2017 15-inch MacBook Pro logic board with faster CPU and more drive capacity, then yes, you can swap them out. In fact, this is what Apple does if you have them replace a logic board due to failure/damage (if they don't convince you to buy a new unit, that is).
If you are purchasing this logic board on the secondary market (eBay, FB Marketplace, etc.) make sure that the device has been dissociated from the previous owners Apple ID. If they don't do this, you could be locked out of the device and it would forever be attached to the other user.