What you’re describing is pretty common. The cogs and chains wear together, so when you replace one side of the equation it may not match up very well with the used side of the equation. Depending how bad it is, you might be able to get thru it with some careful adjustments to the derailleur. If not, then yes, you might need to replace both the chain and the cassette.
Most likely you use those cogs the most and have worn down the sides of the teeth to create bigger gaps which don’t lock in well with the spacing on the new chain. Most likely you need a new cassette but occasionally I have been able to endure this for a few rides until everything syncs up again. Although this works best when the skipping gear is not used as often and risks you may wear your chain quickly in which case you may need to replace that along with the cassette.
I just replaced my chain after 1700 km
now I have noticed that on gears 4 and 5 the chain skips do i also need, to replace the casette or chain rings or something else
A few items…
1. Check the chain for tight links.
2. Fine tune the derailleur.
3. Adjust “B” bolt properly.
4. Replace worn chainring and cassette.
Tight links cause the skip issue frequently. That can be resolved with a chain tool in seconds. B bolt is less likely but can lend to the issue. Fine tuning can sometimes take care of the issue if it is slightly out of adjustment and a minor skip. Major skipping is usually a worn out cassette and it will need replacing. Cleanliness will extend the life of new hardware but no amount of lubrication will resolve a used up drive train.