You should really set the IOS version to be the same before adding a switch to the stack. Basically, the switches need to have the same stack protocol version, and only switches with the same IOS version are guaranteed to have that. Switches with the same major version numbers probably have the same stack protocol version, but that is not guaranteed. Having the same IOS version on a switch before adding it to a stack can save you problems.
Cisco has a very good document, which contains a full explanation about this:
Creation and Management of Catalyst 3750 Switch Stacks
Software Compatibility
Software compatibility between the stack members is determined by the
Stack Protocol Version number. To view the stack protocol version of
your switch stack, you can issue the show platform stack manager
all command.
3750-Stk# show platform stack manager all
Current
Switch# Role Mac Address Priority State
--------------------------------------------------------
1 Slave 0016.4748.dc80 5 Ready
*2 Master 0016.9d59.db00 1 Ready
!--- part of output elided
Stack State Machine View
==============================================================
Switch Master/ Mac Address Version Uptime Current
Number Slave (maj.min) State
---------------------------------------------------------------------
1 Slave 0016.4748.dc80 1.11 8724 Ready
2 Master 0016.9d59.db00 1.11 8803 Ready
!--- rest of output elided
Switches with the same Cisco IOS software version have the same stack
protocol version. Such switches are fully compatible, and all features
function properly across the switch stack. Switches with the same
Cisco IOS software version as the stack master immediately join the
switch stack.
If an incompatibility exists, the fully functional stack members
generate a system message that describes the cause of the
incompatibility on the specific stack members. The stack master sends
the message to all stack members.
Switches with different Cisco IOS software versions likely have
different stack protocol versions. Switches with different major
version numbers are incompatible and cannot exist in the same switch
stack.
3750-Stk# show switch
Current
Switch# Role Mac Address Priority State
--------------------------------------------------------
1 Member 0015.c6f5.6000 1 Version Mismatch
*2 Master 0015.63f6.b700 15 Ready
3 Member 0015.c6c1.3000 5 Ready
Switches with the same major version number but with a different minor
version number as the stack master are considered partially
compatible. When connected to a switch stack, a partially compatible
switch enters version-mismatch (VM) mode and cannot join the stack as
a fully functional member. The software detects the mismatched
software and tries to upgrade (or downgrade) the switch in VM mode
with the switch stack image or with a tar file image from the switch
stack flash memory. The software uses the automatic upgrade
(auto-upgrade) and the automatic advise (auto-advise) features.
The auto-upgrade occurs if the software release that runs on the stack
master is compatible with the switch in VM mode and the tar file of
the current image is available with any of the stack members. If tar
file of the current image is not available, the auto-advise feature
will recommend that a compatible image be downloaded with the required
commands. The auto-upgrade and auto-advise features do not work if the
switch master and switch in VM mode run different feature
sets/packaging levels (IP services and IP base), but, from Cisco IOS
Software Release 12.2(35)SE, auto-upgrade does support upgrades
between cryptographic and non-cryptographic images of the same
packaging level.
Note: If the auto upgrade does not work on the switch that shows the version mismatch error, use TFTP to manually upgrade the switch.