A good way to get to grips with this is to picture a solenoid carrying current producing a N pole at one end of the solenoid and a S pole at the other. Outside the solenoid the compass points just like in your diagram. It is possible to put the compass inside the solenoid and you would find that the lines do go from the S end of the solenoid to the N end inside the solenoid. It is a bit like current in an electric circuit coming out of the + of a battery and travelling to the - of the battery in the external circuit. But the currenttravels from the - of the battery to the + of the battery inside the battery.