Mechanical adding machines, based on rotating wheels, always have the 0 button adjacent to the 1 button.
By convention, most old adding machines had the numbers increasing in value from the bottom and this may be a hangover from when the machines had levers on the wheels rather than buttons.
When the numbers were put on to a pad arranged as a three by three grid with one left over, the order of the numbers, as far as possible, was kept the same.
On a rotary telephone dial the 0 comes adjacent to the 9 because a 0 in the telephone number is signalled by in pulses on the line.
When telephones acquired push buttons in a grid, the ordering of the buttons was carried over from the old telephone dial.