Scotland staged a second-half rally to defeat Wales 26-23, securing a bonus-point victory and moving to the top of the Six Nations table.